1.0.0
This commit is contained in:
1 parent
e25721e114
commit
0eeff6379f
55 files changed
+3504
-3
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
Binary file not shown.
@@ -0,0 +1,2 @@
|
|||||||
|
#Tue Mar 26 11:27:24 MSK 2024
|
||||||
|
gradle.version=8.1.1
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Whitespace-only changes.
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 CarcadeX
|
Copyright (c) 2020 DevSrSouza
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
# KBK-Menu-Preview
|
## Menu Preview
|
||||||
Menu preview for KotlinBukkitKit menu module
|
|
||||||
|
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,112 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("org.jetbrains.intellij") version "1.17.2"
|
||||||
|
java
|
||||||
|
kotlin("jvm") version "1.9.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
val kotlinVersion = "1.9.0"
|
||||||
|
val kotlinBukkitAPIVersion = "1.0.0.2"
|
||||||
|
|
||||||
|
group = "tech.carcadex.kotlinbukkitkit"
|
||||||
|
version = "0.0.1"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
|
intellij {
|
||||||
|
// version = "2023.3.3"
|
||||||
|
version.set("2023.3.3")
|
||||||
|
plugins.set(listOf("java", "Kotlin"))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.jvmTarget = "17"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
compileJava {
|
||||||
|
sourceCompatibility = "17"
|
||||||
|
targetCompatibility = "17"
|
||||||
|
}
|
||||||
|
jar {
|
||||||
|
duplicatesStrategy = (DuplicatesStrategy.EXCLUDE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
runIde {
|
||||||
|
jbrVersion.set("jbr_jcef-17.0.9-windows-x64-b1087.11")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
publishPlugin {
|
||||||
|
token.set(System.getenv("ORG_GRADLE_PROJECT_intellijPublishToken"))
|
||||||
|
channels.set(listOf("stable"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") {
|
||||||
|
|
||||||
|
|
||||||
|
pluginDescription.set("""
|
||||||
|
<img src="https://github.com/DevSrSouza/KotlinBukkitAPI/raw/master/logo.png" width="417" height="161"/>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
The KotlinBukkitKit Tooling is plugin for IntelliJ that helps
|
||||||
|
<br />
|
||||||
|
developers using <a href="https://github.com/CarcadeX/KotlinBukkitKit-Tooling</a>.
|
||||||
|
<br />
|
||||||
|
This libraries help build extensions for Minecraft Server using Spigot server.
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li<a href='https://github.com/CarcadeX/KotlinBukkitKit'>KotlinBukkitKit</a></li>
|
||||||
|
<li<a href='https://github.com/DevSrSouza/KotlinBukkitAPI-Tooling'>KotlinBukkitAPI-Tooling (this plugin)</a></li>
|
||||||
|
<li<a href='https://github.com/DevSrSouza/KotlinBukkitAPI'>KotlinBukkitAPI</a></li>
|
||||||
|
<li><a href='https://github.com/KotlinMinecraft/KotlinBukkitAPI-Examples'>KotlinBukkitAPI Examples</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<h3>Demonstration</h3>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<img src="https://i.imgur.com/exlwVUs.gif" width='680' height='390'/>
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
|
||||||
|
changeNotes.set("""
|
||||||
|
<h3>0.0.1</h3>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>KotlinBukkitAPI Project Wizard</li>
|
||||||
|
<li>Menu Preview tab only avaiable on projects that was KotlinBukkitAPI.</li>
|
||||||
|
</ul>
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations.all {
|
||||||
|
resolutionStrategy.cacheChangingModulesFor(120, "seconds")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
kotlin.code.style=official
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.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" "$@"
|
||||||
Vendored
+100
@@ -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,124 @@
|
|||||||
|
@file:DependsOn("io.ktor:ktor-client-core:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-core-jvm:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-apache:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-json-jvm:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-gson:1.4.0")
|
||||||
|
|
||||||
|
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
|
||||||
|
|
||||||
|
// HTML
|
||||||
|
@file:DependsOn("it.skrape:skrapeit-core:1.0.0-alpha6")
|
||||||
|
@file:DependsOn("io.github.rybalkinsd:kohttp:0.12.0")
|
||||||
|
@file:DependsOn("org.jsoup:jsoup:1.13.1")
|
||||||
|
|
||||||
|
// IMAGE RESIZE
|
||||||
|
@file:DependsOn("com.sksamuel.scrimage:scrimage-core:4.0.6")
|
||||||
|
@file:DependsOn("com.sksamuel.scrimage:scrimage-formats-extra:4.0.6")
|
||||||
|
@file:DependsOn("ar.com.hjg:pngj:2.1.0")
|
||||||
|
@file:DependsOn("com.github.zh79325:open-gif:1.0.4")
|
||||||
|
|
||||||
|
// CODE GENERATIOn
|
||||||
|
@file:DependsOn("com.squareup:kotlinpoet:0.6.0")
|
||||||
|
|
||||||
|
import com.sksamuel.scrimage.ImmutableImage
|
||||||
|
import com.sksamuel.scrimage.ScaleMethod
|
||||||
|
import com.sksamuel.scrimage.nio.PngWriter
|
||||||
|
import com.squareup.kotlinpoet.FileSpec
|
||||||
|
import com.squareup.kotlinpoet.TypeSpec
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.apache.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
|
import it.skrape.core.htmlDocument
|
||||||
|
import it.skrape.extract
|
||||||
|
import it.skrape.skrape
|
||||||
|
import kotlinx.coroutines.flow.asFlow
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.awt.Color
|
||||||
|
import java.awt.image.BufferedImage
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
data class Item(
|
||||||
|
val id: String,
|
||||||
|
val image: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
var items = skrape {
|
||||||
|
val url = "https://www.deadmap.com/idlist"
|
||||||
|
|
||||||
|
extract {
|
||||||
|
htmlDocument {
|
||||||
|
findFirst("#idlist").findAll("tr") {
|
||||||
|
map {
|
||||||
|
val img = it.findFirst("img")
|
||||||
|
.attribute("src")
|
||||||
|
.replace(" ", "%20")
|
||||||
|
|
||||||
|
val id = it.findFirst("i").text
|
||||||
|
|
||||||
|
Item(id.removePrefix("minecraft:"), "https://www.deadmap.com/$img")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println(items.joinToString("\n"))
|
||||||
|
|
||||||
|
// FIXERS
|
||||||
|
val fixers = mapOf(
|
||||||
|
"staned" to "stained",
|
||||||
|
"dandelion_yellow" to "yellow_dye"
|
||||||
|
)
|
||||||
|
|
||||||
|
items = items.map { it.copy(fixers.entries.fold(it.id) { id, entry -> id.replace(entry.key, entry.value) }) }
|
||||||
|
|
||||||
|
runBlocking {
|
||||||
|
val client = HttpClient(Apache)
|
||||||
|
|
||||||
|
val iconsFolder = File("../src/main/resources/assets/items-13").canonicalFile
|
||||||
|
iconsFolder.mkdirs()
|
||||||
|
|
||||||
|
items
|
||||||
|
.withIndex()
|
||||||
|
.asFlow()
|
||||||
|
.onEach { (index, item) ->
|
||||||
|
val (name, imageUrl) = item
|
||||||
|
println("Downloading item: $name ($index/${items.size - 1})")
|
||||||
|
|
||||||
|
val imageBytes = client.get<ByteArray>(imageUrl)
|
||||||
|
|
||||||
|
val image = ImmutableImage.loader()
|
||||||
|
.type(BufferedImage.TYPE_INT_ARGB)
|
||||||
|
.fromBytes(imageBytes)
|
||||||
|
.run {
|
||||||
|
val tags = metadata.tags()
|
||||||
|
val width = tags.first { it.name.contains("Width") }.rawValue.toInt()
|
||||||
|
val height = tags.first { it.name.contains("Height") }.rawValue.toInt()
|
||||||
|
|
||||||
|
if(width > 32 || height > 32) {
|
||||||
|
scaleTo(32, 32, ScaleMethod.FastScale)
|
||||||
|
} else this
|
||||||
|
}
|
||||||
|
|
||||||
|
image.output(PngWriter.NoCompression, File(iconsFolder, "$name.png"))
|
||||||
|
println("Complete download and resize: $name ($index/${items.size - 1})")
|
||||||
|
}
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
println("Generating MinecrateItem13 Enumeration")
|
||||||
|
|
||||||
|
FileSpec.builder("br.com.devsrsouza.kotlinbukkitapi.tooling.menu", "MinecraftItem13")
|
||||||
|
.addType(
|
||||||
|
TypeSpec.enumBuilder("MinecraftItem13")
|
||||||
|
.apply {
|
||||||
|
for ((id, _) in items) {
|
||||||
|
addEnumConstant(id.toUpperCase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.writeTo(File("../src/main/kotlin/").canonicalFile)
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
rootProject.name = "KBK-Menu-Preview Bukkit"
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling
|
||||||
|
|
||||||
|
import com.intellij.ui.IconManager
|
||||||
|
import javax.swing.Icon
|
||||||
|
|
||||||
|
object Assets {
|
||||||
|
private fun load(path: String): Icon {
|
||||||
|
return IconManager.getInstance().getIcon(path, ClassLoader.getSystemClassLoader())
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val assetFolder = "/assets"
|
||||||
|
|
||||||
|
val KotlinBukkitAPIIcon =
|
||||||
|
tech.carcadex.kotlinbukkitkit.tooling.Assets.load("${tech.carcadex.kotlinbukkitkit.tooling.Assets.assetFolder}/icons/kotlinbukkitapi-icon.svg")
|
||||||
|
val Bukkript =
|
||||||
|
tech.carcadex.kotlinbukkitkit.tooling.Assets.load("${tech.carcadex.kotlinbukkitkit.tooling.Assets.assetFolder}/icons/bukkript.svg")
|
||||||
|
val FolderScript =
|
||||||
|
tech.carcadex.kotlinbukkitkit.tooling.Assets.load("${tech.carcadex.kotlinbukkitkit.tooling.Assets.assetFolder}/icons/folderScript.svg")
|
||||||
|
val FolderPlugins =
|
||||||
|
tech.carcadex.kotlinbukkitkit.tooling.Assets.load("${tech.carcadex.kotlinbukkitkit.tooling.Assets.assetFolder}/icons/folderPlugins.svg")
|
||||||
|
val FolderBukkript =
|
||||||
|
tech.carcadex.kotlinbukkitkit.tooling.Assets.load("${tech.carcadex.kotlinbukkitkit.tooling.Assets.assetFolder}/icons/folderBukkript.svg")
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
data class MenuDeclaration(
|
||||||
|
val displayname: String,
|
||||||
|
val lines: Int,
|
||||||
|
val slots: List<MenuSlotDeclaration>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class MenuSlotDeclaration(
|
||||||
|
val line: Int,
|
||||||
|
val slot: Int,
|
||||||
|
val item: String,
|
||||||
|
val isSelected: Boolean = false
|
||||||
|
)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
import com.intellij.util.ImageLoader
|
||||||
|
import tech.carcadex.kotlinbukkitkit.tooling.Assets
|
||||||
|
import java.awt.Graphics
|
||||||
|
import java.awt.Image
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
import javax.imageio.ImageIO
|
||||||
|
import javax.swing.JPanel
|
||||||
|
|
||||||
|
|
||||||
|
class ImagePanel : JPanel() {
|
||||||
|
private var image: Image? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
|
||||||
|
try {
|
||||||
|
image = ImageIO.read((File(MenuPreviewFileEditorProvider.ASSETS_FOLDER.absolutePath + "/items-13/acacia_boat.png")))
|
||||||
|
} catch (ex: IOException) {
|
||||||
|
// handle exception...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun paintComponent(g: Graphics) {
|
||||||
|
super.paintComponent(g)
|
||||||
|
g.drawImage(image, 0, 0, this) // see javadoc for more info on the parameters
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
import com.intellij.util.ImageLoader
|
||||||
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
|
import tech.carcadex.kotlinbukkitkit.tooling.Assets
|
||||||
|
import java.awt.*
|
||||||
|
import java.io.File
|
||||||
|
import javax.imageio.ImageIO
|
||||||
|
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 = MenuPreviewFileEditorProvider.ASSETS_FOLDER.absolutePath + "/fonts/Minecraftia-Regular.ttf"
|
||||||
|
private val spritesFolder = MenuPreviewFileEditorProvider.ASSETS_FOLDER.absolutePath + "/sprites"
|
||||||
|
private val itemsSpriteFolder = MenuPreviewFileEditorProvider.ASSETS_FOLDER.absolutePath + "/items"
|
||||||
|
private val items13SpriteFolder = MenuPreviewFileEditorProvider.ASSETS_FOLDER.absolutePath + "/items-13"
|
||||||
|
|
||||||
|
// the selected-border is 36x36 and not 32x32
|
||||||
|
private const val selectedBorderSizeDiff = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
private val lines = when {
|
||||||
|
declaration.lines > 6 -> 6
|
||||||
|
declaration.lines < 1 -> 1
|
||||||
|
else -> declaration.lines
|
||||||
|
}
|
||||||
|
|
||||||
|
private val spriteImage = ImageIO.read(File(
|
||||||
|
"$spritesFolder/chest-${lines}.png")
|
||||||
|
)!!
|
||||||
|
private val itemsImage = declaration.slots.filter {
|
||||||
|
it.line in 1..declaration.lines && it.slot in 1..9
|
||||||
|
}.keysToMap {
|
||||||
|
// TODO: Support data
|
||||||
|
val item13 = runCatching { MinecraftItem13.valueOf(it.item) }.getOrNull()
|
||||||
|
|
||||||
|
if(item13 != null) {
|
||||||
|
ImageIO.read(File("$items13SpriteFolder/${item13.name.lowercase()}.png"))
|
||||||
|
} else {
|
||||||
|
val item = runCatching { MinecraftItem.valueOf(it.item) }.getOrNull()
|
||||||
|
|
||||||
|
if (item != null) {
|
||||||
|
ImageIO.read(File("$itemsSpriteFolder/${item.id}-0.png"))
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private val selectionImage = if(declaration.slots.any { it.isSelected })
|
||||||
|
ImageIO.read(File("$spritesFolder/selected-border.png"))
|
||||||
|
else null
|
||||||
|
|
||||||
|
private val minecraftFont = Font.createFont(
|
||||||
|
Font.TRUETYPE_FONT,
|
||||||
|
File(minecraftFontResource)
|
||||||
|
).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,200 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
import com.esotericsoftware.kryo.kryo5.minlog.Log
|
||||||
|
import com.intellij.codeInsight.codeVision.ui.mouseClicked
|
||||||
|
import com.intellij.collaboration.ui.VerticalListPanel
|
||||||
|
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.platform.ide.progress.ModalTaskOwner.component
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
|
import com.intellij.ui.components.JBScrollPane
|
||||||
|
import com.intellij.ui.layout.panel
|
||||||
|
import com.intellij.util.Alarm
|
||||||
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||||
|
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 {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val REBUILD_DELAY_MILLISECONDS = 80
|
||||||
|
}
|
||||||
|
|
||||||
|
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 var currentScroll: JBScrollPane? = null
|
||||||
|
private var currentSelectedLine: Int? = null
|
||||||
|
|
||||||
|
private val documentListener = object : DocumentListener {
|
||||||
|
override fun beforeDocumentChange(event: DocumentEvent) {
|
||||||
|
mySwingAlarm.cancelAllRequests()
|
||||||
|
}
|
||||||
|
override fun documentChanged(event: DocumentEvent) {
|
||||||
|
mySwingAlarm.addRequest({
|
||||||
|
rebuild(currentScroll?.viewport?.viewPosition)
|
||||||
|
}, REBUILD_DELAY_MILLISECONDS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val caretListener = object : CaretListener {
|
||||||
|
override fun caretPositionChanged(event: CaretEvent) {
|
||||||
|
|
||||||
|
currentSelectedLine = event.newPosition.line
|
||||||
|
mySwingAlarm.addRequest({
|
||||||
|
rebuild(currentScroll?.viewport?.viewPosition)
|
||||||
|
}, REBUILD_DELAY_MILLISECONDS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var registered = false
|
||||||
|
fun setup() {
|
||||||
|
if(registered) return
|
||||||
|
rebuild(null)
|
||||||
|
|
||||||
|
// listen to the source code changes to rebuild the UI
|
||||||
|
myDocument.addDocumentListener(documentListener)
|
||||||
|
|
||||||
|
// listen to cursor changes to make a slot selectable
|
||||||
|
mainEditor.editor.caretModel.addCaretListener(caretListener)
|
||||||
|
registered = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebuild(currentViewPosition: Point?) {
|
||||||
|
if(!myUi.isShowing) return
|
||||||
|
|
||||||
|
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,
|
||||||
|
myFile
|
||||||
|
)
|
||||||
|
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("Could not render menu preview")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// val p = Panel()
|
||||||
|
// p.setSize(50, 100)
|
||||||
|
// p.background = Color.CYAN
|
||||||
|
// myUi.add(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 selectNotify() {
|
||||||
|
setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deselectNotify() {
|
||||||
|
dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
override fun dispose() {
|
||||||
|
// mySwingAlarm.cancelAllRequests()
|
||||||
|
// try {
|
||||||
|
// if(!registered) return
|
||||||
|
// myDocument.removeDocumentListener(documentListener)
|
||||||
|
// mainEditor.editor.caretModel.removeCaretListener(caretListener)
|
||||||
|
// } catch (e: Throwable) {
|
||||||
|
// Log.warn(e.message)
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun JComponent.centerComponent(): JPanel {
|
||||||
|
return JPanel().apply {
|
||||||
|
isVisible = true
|
||||||
|
layout = GridBagLayout()
|
||||||
|
|
||||||
|
add(this@centerComponent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
import com.intellij.openapi.fileEditor.*
|
||||||
|
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||||
|
import com.intellij.openapi.module.ModuleUtilCore
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.openapi.vfs.readText
|
||||||
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
|
import org.jetbrains.kotlin.incremental.createDirectory
|
||||||
|
import tech.carcadex.kotlinbukkitkit.tooling.Assets
|
||||||
|
import java.io.*
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
|
|
||||||
|
class MenuPreviewFileEditorProvider : WeighedFileEditorProvider() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val MAIN_FOLDER = File("kbk-assets")
|
||||||
|
val ASSETS_FOLDER = File("kbk-assets/assets")
|
||||||
|
const val ID = "kotlinbukkitkit-menu-preview"
|
||||||
|
init {
|
||||||
|
MAIN_FOLDER.createDirectory()
|
||||||
|
val zip = File(MAIN_FOLDER, "assets.zip")
|
||||||
|
if(!zip.exists()) {
|
||||||
|
zip.createNewFile()
|
||||||
|
val input: InputStream = Assets::class.java.getResourceAsStream("/assets.zip")
|
||||||
|
zip.writeBytes(input.readAllBytes())
|
||||||
|
|
||||||
|
fun unzip(`is`: InputStream?, targetDir: Path) {
|
||||||
|
var targetDir: Path = targetDir
|
||||||
|
targetDir = targetDir.toAbsolutePath()
|
||||||
|
ZipInputStream(`is`).use { zipIn ->
|
||||||
|
var ze: ZipEntry
|
||||||
|
while (zipIn.nextEntry.also {
|
||||||
|
if (it != null) {
|
||||||
|
ze = it
|
||||||
|
val resolvedPath: Path = targetDir.resolve(ze.name).normalize()
|
||||||
|
if (!resolvedPath.startsWith(targetDir)) {
|
||||||
|
throw RuntimeException(
|
||||||
|
"Entry with an illegal path: "
|
||||||
|
+ ze.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (ze.isDirectory) {
|
||||||
|
Files.createDirectories(resolvedPath)
|
||||||
|
} else {
|
||||||
|
Files.createDirectories(resolvedPath.getParent())
|
||||||
|
Files.copy(zipIn, resolvedPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} != null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unzip(FileInputStream(zip), MAIN_FOLDER.toPath())
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getEditorTypeId(): String = ID
|
||||||
|
|
||||||
|
override fun accept(project: Project, file: VirtualFile): Boolean {
|
||||||
|
val type = file.fileType
|
||||||
|
|
||||||
|
if(type != KotlinFileType.INSTANCE) return false
|
||||||
|
|
||||||
|
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return false
|
||||||
|
|
||||||
|
val root = ModuleRootManager.getInstance(module)
|
||||||
|
var hasKotlinBukkitAPI = false
|
||||||
|
|
||||||
|
root.orderEntries().withoutSdk().forEachLibrary {
|
||||||
|
if((it.name ?: "").contains("kotlinbukkitkit", true)) {
|
||||||
|
hasKotlinBukkitAPI = true
|
||||||
|
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!file.readText().contains("tech.carcadex.kotlinbukkitkit.menu.dsl.menu")) hasKotlinBukkitAPI = false;
|
||||||
|
|
||||||
|
return hasKotlinBukkitAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createEditor(project: Project, file: VirtualFile): FileEditor {
|
||||||
|
val editor: TextEditor = TextEditorProvider.getInstance().createEditor(project, file) as TextEditor
|
||||||
|
val preview = MenuPreviewFileEditor(project, file, editor)
|
||||||
|
val result = TextEditorWithPreview(editor, preview, "KotlinBukkitKit")
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
//override fun getPolicy(): FileEditorPolicy = FileEditorPolicy.HIDE_DEFAULT_EDITOR
|
||||||
|
override fun getPolicy(): FileEditorPolicy = FileEditorPolicy.HIDE_DEFAULT_EDITOR
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,390 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,116 @@
|
|||||||
|
package tech.carcadex.kotlinbukkitkit.tooling.menu
|
||||||
|
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.openapi.vfs.readText
|
||||||
|
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
|
||||||
|
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
||||||
|
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||||
|
import org.jetbrains.kotlin.idea.base.psi.getLineNumber
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
import org.jetbrains.kotlin.idea.core.resolveType
|
||||||
|
import org.jetbrains.kotlin.idea.inspections.collections.isCalling
|
||||||
|
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.name.FqName
|
||||||
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtLambdaExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
|
|
||||||
|
private val menuFqSupportedNames = listOf(
|
||||||
|
"tech.carcadex.kotlinbukkitkit.dsl.menu"
|
||||||
|
)
|
||||||
|
|
||||||
|
fun findMenuDeclaration(
|
||||||
|
element: KtCallExpression,
|
||||||
|
currentSelectedLine: Int? = null,
|
||||||
|
file: VirtualFile
|
||||||
|
): MenuDeclaration? {
|
||||||
|
val simpleName = "menu"
|
||||||
|
val nm = file.readText()
|
||||||
|
if (!element.isCallFrom(simpleName, menuFqSupportedNames)) return null
|
||||||
|
if (!nm.contains("tech.carcadex.kotlinbukkitkit.menu.dsl.menu"))
|
||||||
|
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("tech.carcadex.kotlinbukkitkit.menu.dsl.MenuDSL")
|
||||||
|
} ?: return null
|
||||||
|
|
||||||
|
val slotFqName = listOf("tech.carcadex.kotlinbukkitkit.menu.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")
|
||||||
|
} ?: return@mapNotNull null
|
||||||
|
|
||||||
|
val typeExpression = materialExpression.selectorExpression as? KtNameReferenceExpression ?: return@mapNotNull null
|
||||||
|
val materialName = typeExpression.text ?: return@mapNotNull null
|
||||||
|
|
||||||
|
val isSelected = it.getLineNumber() == currentSelectedLine
|
||||||
|
|
||||||
|
MenuSlotDeclaration(
|
||||||
|
line,
|
||||||
|
slot,
|
||||||
|
materialName,
|
||||||
|
isSelected
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return MenuDeclaration(displayName, lines, slotCalls)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isMenuCall(it: KtCallExpression) =
|
||||||
|
it.isCallFrom("menu", menuFqSupportedNames)
|
||||||
|
|
||||||
|
fun KtLambdaExpression.isBuilderBlockFor(fqName: String): Boolean {
|
||||||
|
return (text.replace(" ", "").replace("\t", "").replace("\n", "")
|
||||||
|
.contains(Regex("\\{[\\s\\S]*?slot"))) && (parent.parent.text.contains("menu"))
|
||||||
|
// val type = resolveType()
|
||||||
|
//
|
||||||
|
// val extensionFunctionType = type?.isExtensionFunctionType
|
||||||
|
//
|
||||||
|
// if (extensionFunctionType != true) 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,
|
||||||
|
fqNames: List<String>
|
||||||
|
|
||||||
|
): Boolean {
|
||||||
|
return text.startsWith(simpleName)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<idea-plugin>
|
||||||
|
<id>tech.carcadex.kotlinbukkitkit.tooling.menu</id>
|
||||||
|
<name>KBK-Menu-Preview Bukkit</name>
|
||||||
|
<vendor>Denis Istratov</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>
|
||||||
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
<depends>com.intellij.modules.externalSystem</depends>
|
||||||
|
<depends>com.intellij.modules.java</depends>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<fileEditorProvider implementation="tech.carcadex.kotlinbukkitkit.tooling.menu.MenuPreviewFileEditorProvider"/>
|
||||||
|
</extensions>
|
||||||
|
|
||||||
|
<actions>
|
||||||
|
</actions>
|
||||||
|
</idea-plugin>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 354.67 501.96"><defs><style>.cls-1{isolation:isolate;}.cls-2{fill:#797879;}.cls-3{fill:#6d6d6d;}.cls-4{fill:#989999;}.cls-5{fill:#565656;}.cls-6{fill:#525252;}.cls-7{fill:#353535;}.cls-8{opacity:0.65;}.cls-17,.cls-8{mix-blend-mode:multiply;}.cls-9{fill:url(#Gradiente_sem_nome_4);}.cls-10{fill:url(#Gradiente_sem_nome_2);}.cls-11{fill:url(#Gradiente_sem_nome_3);}.cls-12{fill:#979797;}.cls-13{fill:#d8d8d8;}.cls-14{fill:#a8a8a8;}.cls-15{fill:#737373;}.cls-16{fill:#fff;}.cls-17{opacity:0.45;}</style><linearGradient id="Gradiente_sem_nome_4" x1="196.69" y1="389.39" x2="360.57" y2="225.51" gradientUnits="userSpaceOnUse"><stop offset="0.1" stop-color="#0995d3"/><stop offset="0.3" stop-color="#3387c8"/><stop offset="0.62" stop-color="#5876b9"/><stop offset="0.86" stop-color="#6a6eb2"/><stop offset="1" stop-color="#716baf"/></linearGradient><linearGradient id="Gradiente_sem_nome_2" x1="184.43" y1="194.2" x2="266.91" y2="111.72" gradientTransform="matrix(0.98, -0.21, 0.21, 0.98, -180.79, -26.57)" gradientUnits="userSpaceOnUse"><stop offset="0.12" stop-color="#0995d3"/><stop offset="0.42" stop-color="#497fc1"/><stop offset="0.7" stop-color="#676fb3"/><stop offset="0.83" stop-color="#716baf"/></linearGradient><linearGradient id="Gradiente_sem_nome_3" x1="112.74" y1="410.17" x2="392.46" y2="130.45" gradientTransform="matrix(0.98, -0.21, 0.21, 0.98, -180.79, -26.57)" gradientUnits="userSpaceOnUse"><stop offset="0.11" stop-color="#af5ea1"/><stop offset="0.21" stop-color="#d1609b"/><stop offset="0.43" stop-color="#e1725c"/><stop offset="0.6" stop-color="#ef7f30"/><stop offset="0.74" stop-color="#f18519"/><stop offset="0.82" stop-color="#f18816"/></linearGradient></defs><title>kotlinbukkitapi-logo</title><g class="cls-1"><g id="Camada_1" data-name="Camada 1"><rect class="cls-2" x="210.57" y="242.57" width="28.82" height="28.82"/><rect class="cls-2" x="181.75" y="242.57" width="28.82" height="28.82"/><rect class="cls-2" x="152.93" y="242.57" width="28.82" height="28.82"/><rect class="cls-3" x="124.11" y="242.57" width="28.82" height="28.82"/><rect class="cls-4" x="268.21" y="213.75" width="28.82" height="28.82"/><rect class="cls-4" x="239.39" y="213.75" width="28.82" height="28.82"/><rect class="cls-2" x="210.57" y="213.75" width="28.82" height="28.82"/><rect class="cls-2" x="181.75" y="213.75" width="28.82" height="28.82"/><rect class="cls-2" x="152.93" y="213.75" width="28.82" height="28.82"/><rect class="cls-3" x="124.11" y="213.75" width="28.82" height="28.82"/><rect class="cls-3" x="95.29" y="213.75" width="28.82" height="28.82"/><rect class="cls-5" x="66.46" y="213.75" width="28.82" height="28.82"/><rect class="cls-4" x="297.03" y="184.93" width="28.82" height="28.82"/><rect class="cls-4" x="268.21" y="184.93" width="28.82" height="28.82"/><rect class="cls-4" x="239.39" y="184.93" width="28.82" height="28.82"/><rect class="cls-2" x="210.57" y="184.93" width="28.82" height="28.82"/><rect class="cls-2" x="181.75" y="184.93" width="28.82" height="28.82"/><rect class="cls-2" x="152.93" y="184.93" width="28.82" height="28.82"/><rect class="cls-2" x="124.11" y="184.93" width="28.82" height="28.82"/><rect class="cls-3" x="95.29" y="184.93" width="28.82" height="28.82"/><rect class="cls-5" x="66.46" y="184.93" width="28.82" height="28.82"/><rect class="cls-5" x="37.64" y="184.93" width="28.82" height="28.82"/><rect class="cls-6" x="297.03" y="156.11" width="28.82" height="28.82"/><rect class="cls-6" x="268.21" y="156.11" width="28.82" height="28.82"/><rect class="cls-4" x="239.39" y="156.11" width="28.82" height="28.82"/><rect class="cls-2" x="210.57" y="156.11" width="28.82" height="28.82"/><rect class="cls-2" x="181.75" y="156.11" width="28.82" height="28.82"/><rect class="cls-2" x="152.93" y="156.11" width="28.82" height="28.82"/><rect class="cls-2" x="124.11" y="156.11" width="28.82" height="28.82"/><rect class="cls-3" x="95.29" y="156.11" width="28.82" height="28.82"/><rect class="cls-7" x="66.46" y="156.11" width="28.82" height="28.82"/><rect class="cls-7" x="37.64" y="156.11" width="28.82" height="28.82"/><rect class="cls-6" x="239.39" y="127.29" width="28.82" height="28.82"/><rect class="cls-6" x="210.57" y="127.29" width="28.82" height="28.82"/><rect class="cls-6" x="181.75" y="127.29" width="28.82" height="28.82"/><rect class="cls-7" x="152.93" y="127.29" width="28.82" height="28.82"/><rect class="cls-7" x="124.11" y="127.29" width="28.82" height="28.82"/><rect class="cls-7" x="95.29" y="127.29" width="28.82" height="28.82"/></g><g id="Camada_2_cópia_cópia" data-name="Camada 2 cópia cópia"><image class="cls-8" width="1456" height="1563" transform="scale(0.24)" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABbEAAAYcCAYAAAA8LMeNAAAACXBIWXMAAC4jAAAuIwF4pT92AAAgAElEQVR4Xuy9244jyQ4ly6yZ///h6ew6D7XjtIvFy2JclCHJDCCcXO6hUgjoF4Mj++v3798GAAAAAAAAAAAAAHBHfnUHAAAAAAAAAAAAAAB+CiQ2AAAAAAAAAAAAANwWJDYAAAAAAAAAAAAA3BYkNgAAALine truncated
|
||||||
|
After Width: | Height: | Size: 304 KiB |
Whitespace-only changes.
Reference in new issue
Block a user