Tweaks and fixes
This commit is contained in:
197
build.gradle.kts
197
build.gradle.kts
@@ -1,25 +1,23 @@
|
|||||||
@file:Suppress("UNUSED_VARIABLE")
|
@file:Suppress("RemoveRedundantBackticks", "IMPLICIT_CAST_TO_ANY", "UNUSED_VARIABLE")
|
||||||
|
|
||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
|
import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
|
|
||||||
val firstImport = false
|
val stdout = PrintWriter("gradle-output.txt")
|
||||||
val stdout = PrintWriter(File("$rootDir/gradle-output.txt"))
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
dependencies {
|
|
||||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "io.dico"
|
group = "io.dico"
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
|
|
||||||
inline fun <reified T : Plugin<out Project>> Project.apply() =
|
plugins {
|
||||||
(this as PluginAware).apply<T>()
|
java
|
||||||
|
kotlin("jvm") version "1.2.51"
|
||||||
|
id("com.github.johnrengelman.plugin-shadow") version "2.0.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin.experimental.coroutines = ENABLE
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply<JavaPlugin>()
|
apply<JavaPlugin>()
|
||||||
@@ -28,76 +26,72 @@ allprojects {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
|
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
|
||||||
maven("https://hub.spigotmc.org/nexus/content/repositories/sonatype-nexus-snapshots")
|
maven("https://hub.spigotmc.org/nexus/content/repositories/sonatype-nexus-snapshots")
|
||||||
|
maven("https://dl.bintray.com/kotlin/exposed")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
val spigotVersion = "1.13-R0.1-SNAPSHOT"
|
val spigotVersion = "1.13-R0.1-SNAPSHOT"
|
||||||
compile("org.bukkit:bukkit:$spigotVersion") { isTransitive = false }
|
c.provided("org.bukkit:bukkit:$spigotVersion") { isTransitive = false }
|
||||||
compile("org.spigotmc:spigot-api:$spigotVersion") { isTransitive = false }
|
c.provided("org.spigotmc:spigot-api:$spigotVersion") { isTransitive = false }
|
||||||
|
|
||||||
compile("net.sf.trove4j:trove4j:3.0.3")
|
c.provided("net.sf.trove4j:trove4j:3.0.3")
|
||||||
testCompile("junit:junit:4.12")
|
testCompile("junit:junit:4.12")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
tasks.filter { it is Jar }.forEach { it.group = "artifacts" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project(":dicore3:dicore3-command") {
|
project(":dicore3:dicore3-command") {
|
||||||
apply<KotlinPlatformJvmPlugin>()
|
apply<KotlinPlatformJvmPlugin>()
|
||||||
|
|
||||||
kotlin.experimental.coroutines = ENABLE
|
kotlin.experimental.coroutines = ENABLE
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// why the fuck does it need reflect explicitly?
|
c.kotlinStd(kotlin("stdlib-jdk8"))
|
||||||
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
|
c.kotlinStd(kotlin("reflect"))
|
||||||
compile(kotlin("reflect", version = "1.2.50"))
|
c.kotlinStd(kotlinx("coroutines-core:0.23.4"))
|
||||||
compile(kotlin("stdlib-jdk8", version = "1.2.51"))
|
|
||||||
compile(project(":dicore3:dicore3-core"))
|
compile(project(":dicore3:dicore3-core"))
|
||||||
compile("com.thoughtworks.paranamer:paranamer:2.8")
|
compile("com.thoughtworks.paranamer:paranamer:2.8")
|
||||||
|
c.provided("com.google.guava:guava:25.1-jre")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
kotlin("jvm") version "1.2.51"
|
|
||||||
id("com.github.johnrengelman.plugin-shadow") version "2.0.3"
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin.experimental.coroutines = ENABLE
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven("https://dl.bintray.com/kotlin/exposed")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(project(":dicore3:dicore3-core"))
|
compile(project(":dicore3:dicore3-core"))
|
||||||
compile(project(":dicore3:dicore3-command"))
|
compile(project(":dicore3:dicore3-command"))
|
||||||
compile(kotlin("stdlib-jdk8"))
|
|
||||||
|
|
||||||
compile("org.jetbrains.exposed:exposed:0.10.3")
|
c.kotlinStd(kotlin("stdlib-jdk8"))
|
||||||
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
|
c.kotlinStd(kotlinx("coroutines-core:0.23.4"))
|
||||||
|
c.kotlinStd("org.jetbrains.exposed:exposed:0.10.3")
|
||||||
|
|
||||||
compile("com.zaxxer:HikariCP:3.2.0")
|
compile("com.zaxxer:HikariCP:3.2.0")
|
||||||
compile("com.h2database:h2:1.4.197")
|
|
||||||
|
|
||||||
val jacksonVersion = "2.9.6"
|
val jacksonVersion = "2.9.6"
|
||||||
compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
||||||
compile("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
compile("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
||||||
compile("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
|
||||||
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
|
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
|
||||||
//compile("org.yaml:snakeyaml:1.19")
|
compile("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") { isTransitive = false }
|
||||||
|
|
||||||
compile("org.slf4j:slf4j-api:1.7.25")
|
|
||||||
compile("ch.qos.logback:logback-classic:1.2.3")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
removeIf { it is ShadowJar }
|
||||||
|
|
||||||
|
val compileKotlin by getting(KotlinCompile::class) {
|
||||||
|
kotlinOptions {
|
||||||
|
javaParameters = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val serverDir = "$rootDir/debug"
|
val serverDir = "$rootDir/debug"
|
||||||
val jar by getting(Jar::class)
|
val jar by getting(Jar::class)
|
||||||
|
|
||||||
val kotlinStdlibJar by creating(Jar::class) {
|
val kotlinStdlibJar by creating(Jar::class) {
|
||||||
destinationDir = file("$serverDir/lib")
|
destinationDir = file("$serverDir/lib")
|
||||||
archiveName = "kotlin-stdlib.jar"
|
archiveName = "kotlin-stdlib.jar"
|
||||||
packageDependencies("kotlin-stdlib-jdk8")
|
fromFiles(c.kotlinStd)
|
||||||
}
|
|
||||||
|
|
||||||
val debugEnvironment by creating(Exec::class) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val releaseJar by creating(ShadowJar::class) {
|
val releaseJar by creating(ShadowJar::class) {
|
||||||
@@ -105,103 +99,46 @@ tasks {
|
|||||||
baseName = "parcels2-release"
|
baseName = "parcels2-release"
|
||||||
|
|
||||||
with(jar)
|
with(jar)
|
||||||
|
fromFiles(c.compile)
|
||||||
|
|
||||||
packageArtifacts(
|
/*
|
||||||
"jackson-core",
|
Shadow Jar is retarded so it also relocates packages not included in the releaseJar (such as the bukkit api)
|
||||||
"jackson-databind",
|
|
||||||
"jackson-module-kotlin",
|
|
||||||
"jackson-annotations",
|
|
||||||
"jackson-dataformat-yaml",
|
|
||||||
"snakeyaml",
|
|
||||||
|
|
||||||
"slf4j-api",
|
relocate("", "io.dico.parcels2.lib.") {
|
||||||
"logback-core",
|
exclude("*yml")
|
||||||
"logback-classic",
|
exclude("*xml")
|
||||||
|
exclude("META-INF/*")
|
||||||
|
exclude("io/dico/*")
|
||||||
|
}
|
||||||
|
*/*/*/
|
||||||
|
|
||||||
//"h2",
|
// jackson-dataformat-yaml requires an older version of snakeyaml (1.19 or earlier)
|
||||||
"HikariCP",
|
// snakeyaml made a breaking change in 1.20 and didn't really warn anyone afaik
|
||||||
"kotlinx-coroutines-core",
|
// it was like me changing the command library because I know I'm the only one using it
|
||||||
"kotlinx-coroutines-core-common",
|
// spigot ships a later version in the root, so we must relocate ours
|
||||||
"atomicfu-common",
|
relocate("org.yaml.snakeyaml.", "io.dico.parcels2.lib.org.yaml.snakeyaml.")
|
||||||
"exposed",
|
|
||||||
|
|
||||||
"dicore3-core",
|
manifest.attributes["Class-Path"] = "../lib/kotlin-stdlib.jar"
|
||||||
"dicore3-command",
|
|
||||||
"paranamer",
|
|
||||||
|
|
||||||
"trove4j",
|
|
||||||
"joda-time",
|
|
||||||
|
|
||||||
"annotations",
|
|
||||||
"kotlin-stdlib-common",
|
|
||||||
"kotlin-stdlib",
|
|
||||||
"kotlin-stdlib-jdk7",
|
|
||||||
"kotlin-stdlib-jdk8",
|
|
||||||
"kotlin-reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
relocate("org.yaml.snakeyaml", "io.dico.parcels2.util.snakeyaml")
|
|
||||||
|
|
||||||
manifest.attributes["Class-Path"] = "lib/kotlin-stdlib.jar"
|
|
||||||
dependsOn(kotlinStdlibJar)
|
dependsOn(kotlinStdlibJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
allprojects {
|
|
||||||
tasks.filter { it is Jar }.forEach { it.group = "artifacts" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
stdout.close()
|
stdout.close()
|
||||||
|
|
||||||
fun Jar.packageDependencies(vararg names: String) {
|
inline fun <reified T : Plugin<out Project>> Project.apply() =
|
||||||
if (!firstImport) {
|
(this as PluginAware).apply<T>()
|
||||||
from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
|
|
||||||
.filter { it.moduleName in names }
|
|
||||||
.flatMap { it.allModuleArtifacts }
|
|
||||||
.map { it.file }
|
|
||||||
.map(::zipTree)
|
|
||||||
.toTypedArray()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Jar.packageDependency(name: String, configure: ModuleDependency.() -> Unit) {
|
fun kotlinx(module: String, version: String? = null): Any =
|
||||||
if (!firstImport) {
|
"org.jetbrains.kotlinx:kotlinx-$module${version?.let { ":$version" } ?: ""}"
|
||||||
val configuration = project.configurations.compile.copyRecursive()
|
|
||||||
|
|
||||||
configuration.dependencies.removeIf {
|
val Project.c get() = configurations
|
||||||
if (it is ModuleDependency && it.name == name) {
|
|
||||||
it.configure()
|
|
||||||
false
|
|
||||||
} else true
|
|
||||||
}
|
|
||||||
|
|
||||||
from(*configuration.resolvedConfiguration.resolvedArtifacts
|
val ConfigurationContainer.`provided`: Configuration
|
||||||
.map { it.file }
|
get() = findByName("provided") ?: create("provided").let { compileClasspath.extendsFrom(it) }
|
||||||
.map(::zipTree)
|
|
||||||
.toTypedArray())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("IMPLICIT_CAST_TO_ANY")
|
val ConfigurationContainer.`kotlinStd`: Configuration
|
||||||
fun Jar.packageArtifacts(vararg names: String) {
|
get() = findByName("kotlinStd") ?: create("kotlinStd").let { compileClasspath.extendsFrom(it) }
|
||||||
if (!firstImport) {
|
|
||||||
from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
|
fun Jar.fromFiles(files: Iterable<File>) =
|
||||||
.flatMap { dep -> dep.allModuleArtifacts.map { dep to it } }
|
afterEvaluate { from(*files.map { if (it.isDirectory) it else zipTree(it) }.toTypedArray()) }
|
||||||
.filter { pair ->
|
|
||||||
val (dep, art) = pair
|
|
||||||
val id = art.moduleVersion.id
|
|
||||||
(id.name in names).also {
|
|
||||||
val artName = art.moduleVersion.id.let {"${it.group}:${it.name}:${it.version}"}
|
|
||||||
val depName = dep.let { "${it.moduleGroup}:${it.moduleName}:${it.moduleVersion}" }
|
|
||||||
val name = "$artName \n from $depName"
|
|
||||||
stdout.println("${if (it) "Including" else "Not including"} artifact $name")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.map { pair -> pair.second.file }
|
|
||||||
.map { if (it.isDirectory()) it else zipTree(it) }
|
|
||||||
.toTypedArray())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
|
||||||
import org.jetbrains.kotlin.js.translate.context.Namer.kotlin
|
|
||||||
|
|
||||||
group = "io.dico.dicore3"
|
group = "io.dico.dicore3"
|
||||||
//name = "dicore3-command"
|
|
||||||
version = "1.2.5-mc-1.13"
|
version = "1.2.5-mc-1.13"
|
||||||
|
|||||||
@@ -27,27 +27,27 @@ public abstract class Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <TType> Command addParameter(String name, String description, ParameterType<TType, Void> type) {
|
public <TType> Command addParameter(String name, String description, ParameterType<TType, Void> type) {
|
||||||
return addParameter(Parameter.newParameter(name, description, type, null, false, null));
|
return addParameter(new Parameter<>(name, description, type, null, false, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TType, TParamInfo> Command addParameter(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo) {
|
public <TType, TParamInfo> Command addParameter(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo) {
|
||||||
return addParameter(Parameter.newParameter(name, description, type, paramInfo, false, null));
|
return addParameter(new Parameter<>(name, description, type, paramInfo, false, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TType> Command addFlag(String name, String description, ParameterType<TType, Void> type) {
|
public <TType> Command addFlag(String name, String description, ParameterType<TType, Void> type) {
|
||||||
return addParameter(Parameter.newParameter('-' + name, description, type, null, true, null));
|
return addParameter(new Parameter<>('-' + name, description, type, null, true, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TType, TParamInfo> Command addFlag(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo) {
|
public <TType, TParamInfo> Command addFlag(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo) {
|
||||||
return addParameter(Parameter.newParameter('-' + name, description, type, paramInfo, true, null));
|
return addParameter(new Parameter<>('-' + name, description, type, paramInfo, true, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TType> Command addAuthorizedFlag(String name, String description, ParameterType<TType, Void> type, String permission) {
|
public <TType> Command addAuthorizedFlag(String name, String description, ParameterType<TType, Void> type, String permission) {
|
||||||
return addParameter(Parameter.newParameter('-' + name, description, type, null, true, permission));
|
return addParameter(new Parameter<>('-' + name, description, type, null, true, permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TType, TParamInfo> Command addAuthorizedFlag(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo, String permission) {
|
public <TType, TParamInfo> Command addAuthorizedFlag(String name, String description, ParameterType<TType, TParamInfo> type, TParamInfo paramInfo, String permission) {
|
||||||
return addParameter(Parameter.newParameter('-' + name, description, type, paramInfo, true, permission));
|
return addParameter(new Parameter<>('-' + name, description, type, paramInfo, true, permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command requiredParameters(int requiredParameters) {
|
public Command requiredParameters(int requiredParameters) {
|
||||||
|
|||||||
@@ -153,14 +153,7 @@ public final class CommandBuilder {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public CommandBuilder generatePredefinedCommands(String... commands) {
|
public CommandBuilder generatePredefinedCommands(String... commands) {
|
||||||
for (String value : commands) {
|
ReflectiveRegistration.generateCommands(cur, commands);
|
||||||
Consumer<ICommandAddress> subscriber = PredefinedCommand.getPredefinedCommandGenerator(value);
|
|
||||||
if (subscriber == null) {
|
|
||||||
System.out.println("[Command Warning] generated command '" + value + "' could not be found");
|
|
||||||
} else {
|
|
||||||
subscriber.accept(cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public class Parameter<TResult, TParamInfo> {
|
|||||||
private final String description;
|
private final String description;
|
||||||
private final ParameterType<TResult, TParamInfo> parameterType;
|
private final ParameterType<TResult, TParamInfo> parameterType;
|
||||||
private final TParamInfo paramInfo;
|
private final TParamInfo paramInfo;
|
||||||
|
private final boolean isPrimitive;
|
||||||
|
|
||||||
private final boolean flag;
|
private final boolean flag;
|
||||||
private final String flagPermission;
|
private final String flagPermission;
|
||||||
|
|
||||||
@@ -29,6 +31,10 @@ public class Parameter<TResult, TParamInfo> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Parameter(String name, String description, ParameterType<TResult, TParamInfo> parameterType, TParamInfo paramInfo, boolean flag, String flagPermission) {
|
public Parameter(String name, String description, ParameterType<TResult, TParamInfo> parameterType, TParamInfo paramInfo, boolean flag, String flagPermission) {
|
||||||
|
this(name, description, parameterType, paramInfo, false, flag, flagPermission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Parameter(String name, String description, ParameterType<TResult, TParamInfo> parameterType, TParamInfo paramInfo, boolean isPrimitive, boolean flag, String flagPermission) {
|
||||||
this.name = Objects.requireNonNull(name);
|
this.name = Objects.requireNonNull(name);
|
||||||
this.description = description == null ? "" : description;
|
this.description = description == null ? "" : description;
|
||||||
this.parameterType = flag ? parameterType.asFlagParameter() : parameterType;
|
this.parameterType = flag ? parameterType.asFlagParameter() : parameterType;
|
||||||
@@ -38,6 +44,7 @@ public class Parameter<TResult, TParamInfo> {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
this.paramInfo = paramInfo;
|
this.paramInfo = paramInfo;
|
||||||
|
this.isPrimitive = isPrimitive;
|
||||||
|
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
this.flagPermission = flagPermission;
|
this.flagPermission = flagPermission;
|
||||||
@@ -49,17 +56,7 @@ public class Parameter<TResult, TParamInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <TResult> Parameter<TResult, ?> newParameter(String name, String description, ParameterType<TResult, ?> type) {
|
|
||||||
return new Parameter<>(name, description, type, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <TResult, TParamInfo> Parameter<TResult, TParamInfo> newParameter(String name, String description, ParameterType<TResult, TParamInfo> type, TParamInfo info) {
|
|
||||||
return new Parameter<>(name, description, type, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <TResult, TParamInfo> Parameter<TResult, TParamInfo> newParameter(String name, String description, ParameterType<TResult, TParamInfo> parameterType, TParamInfo paramInfo, boolean flag, String flagPermission) {
|
|
||||||
return new Parameter<>(name, description, parameterType, paramInfo, flag, flagPermission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TResult parse(ExecutionContext context, ArgumentBuffer buffer) throws CommandException {
|
public TResult parse(ExecutionContext context, ArgumentBuffer buffer) throws CommandException {
|
||||||
if (getFlagPermission() != null) {
|
if (getFlagPermission() != null) {
|
||||||
@@ -96,6 +93,10 @@ public class Parameter<TResult, TParamInfo> {
|
|||||||
return paramInfo;
|
return paramInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPrimitive() {
|
||||||
|
return isPrimitive;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFlag() {
|
public boolean isFlag() {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ public abstract class NumberParameterType<T extends Number> extends ParameterTyp
|
|||||||
@Override
|
@Override
|
||||||
public T getDefaultValue(Parameter<T, Range.Memory> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
public T getDefaultValue(Parameter<T, Range.Memory> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
||||||
Range.Memory memory = (Range.Memory) parameter.getParamInfo();
|
Range.Memory memory = (Range.Memory) parameter.getParamInfo();
|
||||||
return select(memory != null ? memory.defaultValue() : 0);
|
if (memory != null) return select(memory.defaultValue());
|
||||||
|
return !parameter.isPrimitive() ? null : select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package io.dico.dicore.command.parameter.type;
|
package io.dico.dicore.command.parameter.type;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -7,16 +11,28 @@ import java.util.Objects;
|
|||||||
* More appropriate name: ParameterTypeKey
|
* More appropriate name: ParameterTypeKey
|
||||||
*/
|
*/
|
||||||
public class ParameterKey {
|
public class ParameterKey {
|
||||||
|
|
||||||
private final Class<?> returnType;
|
private final Class<?> returnType;
|
||||||
private final Class<? extends Annotation> annotationClass;
|
private final Class<? extends Annotation> annotationClass;
|
||||||
|
|
||||||
|
// just a marker, not used in equals or hashCode().
|
||||||
|
// returnType is never primitive
|
||||||
|
private boolean isPrimitive;
|
||||||
|
|
||||||
public ParameterKey(Class<?> returnType) {
|
public ParameterKey(Class<?> returnType) {
|
||||||
this(returnType, null);
|
this(returnType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterKey(Class<?> returnType, Class<? extends Annotation> annotationClass) {
|
public ParameterKey(Class<?> returnType, Class<? extends Annotation> annotationClass) {
|
||||||
|
boolean isPrimitive = returnType.isPrimitive();
|
||||||
|
|
||||||
|
if (isPrimitive) {
|
||||||
|
returnType = primitivesToWrappers.get(returnType);
|
||||||
|
}
|
||||||
|
|
||||||
this.returnType = Objects.requireNonNull(returnType);
|
this.returnType = Objects.requireNonNull(returnType);
|
||||||
this.annotationClass = annotationClass;
|
this.annotationClass = annotationClass;
|
||||||
|
this.isPrimitive = isPrimitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getReturnType() {
|
public Class<?> getReturnType() {
|
||||||
@@ -43,4 +59,45 @@ public class ParameterKey {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Class<?> getPrimitiveWrapperClass(Class<?> primitiveClass) {
|
||||||
|
if (!primitiveClass.isPrimitive()) return null;
|
||||||
|
switch (primitiveClass.getName()) {
|
||||||
|
case "boolean":
|
||||||
|
return Boolean.class;
|
||||||
|
case "char":
|
||||||
|
return Character.class;
|
||||||
|
case "byte":
|
||||||
|
return Byte.class;
|
||||||
|
case "short":
|
||||||
|
return Short.class;
|
||||||
|
case "int":
|
||||||
|
return Integer.class;
|
||||||
|
case "float":
|
||||||
|
return Float.class;
|
||||||
|
case "long":
|
||||||
|
return Long.class;
|
||||||
|
case "double":
|
||||||
|
return Double.class;
|
||||||
|
case "void":
|
||||||
|
return Void.class;
|
||||||
|
default:
|
||||||
|
throw new InternalError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final BiMap<Class<?>, Class<?>> primitivesToWrappers;
|
||||||
|
static {
|
||||||
|
HashBiMap<Class<?>, Class<?>> tmp = HashBiMap.create();
|
||||||
|
tmp.put(Boolean.TYPE, Boolean.class);
|
||||||
|
tmp.put(Character.TYPE, Character.class);
|
||||||
|
tmp.put(Byte.TYPE, Byte.class);
|
||||||
|
tmp.put(Short.TYPE, Short.class);
|
||||||
|
tmp.put(Integer.TYPE, Integer.class);
|
||||||
|
tmp.put(Float.TYPE, Float.class);
|
||||||
|
tmp.put(Long.TYPE, Long.class);
|
||||||
|
tmp.put(Double.TYPE, Double.class);
|
||||||
|
tmp.put(Void.TYPE, Void.class);
|
||||||
|
primitivesToWrappers = Maps.unmodifiableBiMap(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,6 @@ public class ParameterTypes {
|
|||||||
public static final NumberParameterType<Float> FLOAT;
|
public static final NumberParameterType<Float> FLOAT;
|
||||||
public static final ParameterType<Player, Void> PLAYER;
|
public static final ParameterType<Player, Void> PLAYER;
|
||||||
public static final ParameterType<OfflinePlayer, Void> OFFLINE_PLAYER;
|
public static final ParameterType<OfflinePlayer, Void> OFFLINE_PLAYER;
|
||||||
//public static final ParameterType<Boolean, Void> PRESENCE;
|
|
||||||
//public static final NumberParameterType<BigDecimal> BIG_DECIMAL;
|
|
||||||
//public static final NumberParameterType<BigInteger> BIG_INTEGER;
|
|
||||||
|
|
||||||
private ParameterTypes() {
|
private ParameterTypes() {
|
||||||
|
|
||||||
@@ -59,7 +56,7 @@ public class ParameterTypes {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDefaultValue(Parameter<String, Void> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
public String getDefaultValue(Parameter<String, Void> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,7 +78,7 @@ public class ParameterTypes {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getDefaultValue(Parameter<Boolean, Void> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
public Boolean getDefaultValue(Parameter<Boolean, Void> parameter, CommandSender sender, ArgumentBuffer buffer) throws CommandException {
|
||||||
return false;
|
return !parameter.isPrimitive() ? null : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package io.dico.dicore.command.predef;
|
||||||
|
|
||||||
|
public class HelpCommandExtended {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
}
|
||||||
@@ -332,7 +332,7 @@ public class ReflectiveRegistration {
|
|||||||
|
|
||||||
ParameterType<Object, Object> parameterType = selector.selectAny(type, typeAnnotation == null ? null : typeAnnotation.getClass());
|
ParameterType<Object, Object> parameterType = selector.selectAny(type, typeAnnotation == null ? null : typeAnnotation.getClass());
|
||||||
if (parameterType == null) {
|
if (parameterType == null) {
|
||||||
throw new CommandParseException("IParameter type not found for parameter " + name + " in method " + method.toGenericString());
|
throw new CommandParseException("IParameter type not found for parameter " + name + " in method " + method.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
Object parameterInfo;
|
Object parameterInfo;
|
||||||
@@ -348,7 +348,8 @@ public class ReflectiveRegistration {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return Parameter.newParameter(name, descString, parameterType, parameterInfo, name.startsWith("-"), flag == null ? null : flag.permission());
|
String flagPermission = flag == null ? null : flag.permission();
|
||||||
|
return new Parameter<>(name, descString, parameterType, parameterInfo, type.isPrimitive(), name.startsWith("-"), flagPermission);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new CommandParseException("Invalid parameter", ex);
|
throw new CommandParseException("Invalid parameter", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,3 +67,10 @@ private fun Deferred<Any?>.getResult(): String? {
|
|||||||
}
|
}
|
||||||
return ReflectiveCommand.getResult(getCompleted(), null)
|
return ReflectiveCommand.getResult(getCompleted(), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getNonPrimitiveClass(clazz: Class<*>): Class<*>? {
|
||||||
|
return if (clazz.isPrimitive)
|
||||||
|
clazz.kotlin.javaObjectType
|
||||||
|
else
|
||||||
|
null
|
||||||
|
}
|
||||||
@@ -2,15 +2,3 @@
|
|||||||
group = "io.dico.dicore3"
|
group = "io.dico.dicore3"
|
||||||
version = "1.2.5"
|
version = "1.2.5"
|
||||||
|
|
||||||
plugins {
|
|
||||||
java
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories() {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile(files("../../res/spigot-1.13-pre7.jar"))
|
|
||||||
|
|
||||||
}
|
|
||||||
206
old-build.gradle.kts
Normal file
206
old-build.gradle.kts
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
@file:Suppress("UNUSED_VARIABLE")
|
||||||
|
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
||||||
|
import java.io.PrintWriter
|
||||||
|
|
||||||
|
val firstImport = false
|
||||||
|
val stdout = PrintWriter(File("$rootDir/gradle-output.txt"))
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
dependencies {
|
||||||
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "io.dico"
|
||||||
|
version = "0.1"
|
||||||
|
|
||||||
|
inline fun <reified T : Plugin<out Project>> Project.apply() =
|
||||||
|
(this as PluginAware).apply<T>()
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
apply<JavaPlugin>()
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
|
||||||
|
maven("https://hub.spigotmc.org/nexus/content/repositories/sonatype-nexus-snapshots")
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
val spigotVersion = "1.13-R0.1-SNAPSHOT"
|
||||||
|
compile("org.bukkit:bukkit:$spigotVersion") { isTransitive = false }
|
||||||
|
compile("org.spigotmc:spigot-api:$spigotVersion") { isTransitive = false }
|
||||||
|
|
||||||
|
compile("net.sf.trove4j:trove4j:3.0.3")
|
||||||
|
testCompile("junit:junit:4.12")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
project(":dicore3:dicore3-command") {
|
||||||
|
apply<KotlinPlatformJvmPlugin>()
|
||||||
|
|
||||||
|
kotlin.experimental.coroutines = ENABLE
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
|
||||||
|
compile(kotlin("reflect", version = "1.2.50"))
|
||||||
|
compile(kotlin("stdlib-jdk8", version = "1.2.51"))
|
||||||
|
compile(project(":dicore3:dicore3-core"))
|
||||||
|
compile("com.thoughtworks.paranamer:paranamer:2.8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("jvm") version "1.2.51"
|
||||||
|
id("com.github.johnrengelman.plugin-shadow") version "2.0.3"
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin.experimental.coroutines = ENABLE
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven("https://dl.bintray.com/kotlin/exposed")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile(project(":dicore3:dicore3-core"))
|
||||||
|
compile(project(":dicore3:dicore3-command"))
|
||||||
|
compile(kotlin("stdlib-jdk8"))
|
||||||
|
|
||||||
|
compile("org.jetbrains.exposed:exposed:0.10.3")
|
||||||
|
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
|
||||||
|
compile("com.zaxxer:HikariCP:3.2.0")
|
||||||
|
compile("com.h2database:h2:1.4.197")
|
||||||
|
|
||||||
|
val jacksonVersion = "2.9.6"
|
||||||
|
compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
||||||
|
compile("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
||||||
|
compile("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
|
||||||
|
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
|
||||||
|
//compile("org.yaml:snakeyaml:1.19")
|
||||||
|
|
||||||
|
compile("org.slf4j:slf4j-api:1.7.25")
|
||||||
|
compile("ch.qos.logback:logback-classic:1.2.3")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
val serverDir = "$rootDir/debug"
|
||||||
|
val jar by getting(Jar::class)
|
||||||
|
val kotlinStdlibJar by creating(Jar::class) {
|
||||||
|
destinationDir = file("$serverDir/lib")
|
||||||
|
archiveName = "kotlin-stdlib.jar"
|
||||||
|
packageDependencies("kotlin-stdlib-jdk8")
|
||||||
|
}
|
||||||
|
|
||||||
|
val debugEnvironment by creating(Exec::class) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
val releaseJar by creating(ShadowJar::class) {
|
||||||
|
destinationDir = file("$serverDir/plugins")
|
||||||
|
baseName = "parcels2-release"
|
||||||
|
|
||||||
|
with(jar)
|
||||||
|
|
||||||
|
packageArtifacts(
|
||||||
|
"jackson-core",
|
||||||
|
"jackson-databind",
|
||||||
|
"jackson-module-kotlin",
|
||||||
|
"jackson-annotations",
|
||||||
|
"jackson-dataformat-yaml",
|
||||||
|
"snakeyaml",
|
||||||
|
|
||||||
|
"slf4j-api",
|
||||||
|
"logback-core",
|
||||||
|
"logback-classic",
|
||||||
|
|
||||||
|
//"h2",
|
||||||
|
"HikariCP",
|
||||||
|
"kotlinx-coroutines-core",
|
||||||
|
"kotlinx-coroutines-core-common",
|
||||||
|
"atomicfu-common",
|
||||||
|
"exposed",
|
||||||
|
|
||||||
|
"dicore3-core",
|
||||||
|
"dicore3-command",
|
||||||
|
"paranamer",
|
||||||
|
|
||||||
|
"trove4j",
|
||||||
|
"joda-time",
|
||||||
|
|
||||||
|
"annotations",
|
||||||
|
"kotlin-stdlib-common",
|
||||||
|
"kotlin-stdlib",
|
||||||
|
"kotlin-stdlib-jdk7",
|
||||||
|
"kotlin-stdlib-jdk8",
|
||||||
|
"kotlin-reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
relocate("org.yaml.snakeyaml", "io.dico.parcels2.util.snakeyaml")
|
||||||
|
|
||||||
|
manifest.attributes["Class-Path"] = "lib/kotlin-stdlib.jar"
|
||||||
|
dependsOn(kotlinStdlibJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
tasks.filter { it is Jar }.forEach { it.group = "artifacts" }
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout.flush()
|
||||||
|
stdout.close()
|
||||||
|
|
||||||
|
fun Jar.packageDependencies(vararg names: String) {
|
||||||
|
if (!firstImport) {
|
||||||
|
from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
|
||||||
|
.filter { it.moduleName in names }
|
||||||
|
.flatMap { it.allModuleArtifacts }
|
||||||
|
.map { it.file }
|
||||||
|
.map(::zipTree)
|
||||||
|
.toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Jar.packageDependency(name: String, configure: ModuleDependency.() -> Unit) {
|
||||||
|
if (!firstImport) {
|
||||||
|
val configuration = project.configurations.compile.copyRecursive()
|
||||||
|
|
||||||
|
configuration.dependencies.removeIf {
|
||||||
|
if (it is ModuleDependency && it.name == name) {
|
||||||
|
it.configure()
|
||||||
|
false
|
||||||
|
} else true
|
||||||
|
}
|
||||||
|
|
||||||
|
from(*configuration.resolvedConfiguration.resolvedArtifacts
|
||||||
|
.map { it.file }
|
||||||
|
.map(::zipTree)
|
||||||
|
.toTypedArray())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("IMPLICIT_CAST_TO_ANY")
|
||||||
|
fun Jar.packageArtifacts(vararg names: String) {
|
||||||
|
if (!firstImport) {
|
||||||
|
from(*project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies
|
||||||
|
.flatMap { dep -> dep.allModuleArtifacts.map { dep to it } }
|
||||||
|
.filter { pair ->
|
||||||
|
val (dep, art) = pair
|
||||||
|
val id = art.moduleVersion.id
|
||||||
|
(id.name in names).also {
|
||||||
|
val artName = art.moduleVersion.id.let {"${it.group}:${it.name}:${it.version}"}
|
||||||
|
val depName = dep.let { "${it.moduleGroup}:${it.moduleName}:${it.moduleVersion}" }
|
||||||
|
val name = "$artName \n from $depName"
|
||||||
|
stdout.println("${if (it) "Including" else "Not including"} artifact $name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.map { pair -> pair.second.file }
|
||||||
|
.map { if (it.isDirectory()) it else zipTree(it) }
|
||||||
|
.toTypedArray())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import org.bukkit.block.Block
|
|||||||
import org.bukkit.entity.Entity
|
import org.bukkit.entity.Entity
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.coroutines.experimental.buildIterator
|
||||||
import kotlin.coroutines.experimental.buildSequence
|
import kotlin.coroutines.experimental.buildSequence
|
||||||
import kotlin.reflect.jvm.javaMethod
|
import kotlin.reflect.jvm.javaMethod
|
||||||
import kotlin.reflect.jvm.kotlinFunction
|
import kotlin.reflect.jvm.kotlinFunction
|
||||||
@@ -117,7 +118,9 @@ class ParcelWorld constructor(val name: String,
|
|||||||
val options: WorldOptions,
|
val options: WorldOptions,
|
||||||
val generator: ParcelGenerator,
|
val generator: ParcelGenerator,
|
||||||
val storage: Storage) : ParcelProvider by generator, ParcelContainer {
|
val storage: Storage) : ParcelProvider by generator, ParcelContainer {
|
||||||
val world: World by lazy { Bukkit.getWorld(name) ?: throw NullPointerException("World $name does not appear to be loaded") }
|
val world: World by lazy {
|
||||||
|
Bukkit.getWorld(name) ?: throw NullPointerException("World $name does not appear to be loaded")
|
||||||
|
}
|
||||||
val container: ParcelContainer = DefaultParcelContainer(this, storage)
|
val container: ParcelContainer = DefaultParcelContainer(this, storage)
|
||||||
|
|
||||||
override fun parcelByID(x: Int, z: Int): Parcel? {
|
override fun parcelByID(x: Int, z: Int): Parcel? {
|
||||||
@@ -189,12 +192,24 @@ class DefaultParcelContainer(private val world: ParcelWorld,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun parcelByID(x: Int, z: Int): Parcel? {
|
override fun parcelByID(x: Int, z: Int): Parcel? {
|
||||||
return parcels.getOrNull(x)?.getOrNull(z)
|
return parcels.getOrNull(x + world.options.axisLimit)?.getOrNull(z + world.options.axisLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun nextEmptyParcel(): Parcel? {
|
override fun nextEmptyParcel(): Parcel? {
|
||||||
return parcels[0][0]
|
return walkInCircle().find { it.owner == null }
|
||||||
TODO()
|
}
|
||||||
|
|
||||||
|
private fun walkInCircle(): Iterable<Parcel> = Iterable {
|
||||||
|
buildIterator {
|
||||||
|
val center = world.options.axisLimit
|
||||||
|
for (radius in 0..center) {
|
||||||
|
var x = center - radius; var z = center - radius
|
||||||
|
repeat(radius * 2) { yield(parcels[x++][z]) }
|
||||||
|
repeat(radius * 2) { yield(parcels[x][z++]) }
|
||||||
|
repeat(radius * 2) { yield(parcels[x--][z]) }
|
||||||
|
repeat(radius * 2) { yield(parcels[x][z--]) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allParcels(): Sequence<Parcel> = buildSequence {
|
fun allParcels(): Sequence<Parcel> = buildSequence {
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ class DefaultParcelGenerator(val worlds: Worlds, val name: String, private val o
|
|||||||
val signBlock = world.getBlockAt(b.x - 2, o.floorHeight + 1, b.z - 1)
|
val signBlock = world.getBlockAt(b.x - 2, o.floorHeight + 1, b.z - 1)
|
||||||
val skullBlock = world.getBlockAt(b.x - 1, o.floorHeight + 2, b.z - 1)
|
val skullBlock = world.getBlockAt(b.x - 1, o.floorHeight + 2, b.z - 1)
|
||||||
|
|
||||||
val owner = parcel.data?.owner
|
val owner = parcel.owner
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
wallBlock.blockData = o.wallType
|
wallBlock.blockData = o.wallType
|
||||||
signBlock.type = Material.AIR
|
signBlock.type = Material.AIR
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class CommandsParcelOptions(plugin: ParcelsPlugin) : AbstractParcelCommands(plug
|
|||||||
@Desc("Sets whether players who are not allowed to",
|
@Desc("Sets whether players who are not allowed to",
|
||||||
"build here can interact with inventories",
|
"build here can interact with inventories",
|
||||||
shortVersion = "allows editing inventories")
|
shortVersion = "allows editing inventories")
|
||||||
|
@RequireParameters(0)
|
||||||
fun ParcelScope.cmdInventory(player: Player, enabled: Boolean?): Any? {
|
fun ParcelScope.cmdInventory(player: Player, enabled: Boolean?): Any? {
|
||||||
return runOptionCommand(player, Parcel::allowInteractInventory, enabled, "interaction with inventories")
|
return runOptionCommand(player, Parcel::allowInteractInventory, enabled, "interaction with inventories")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package io.dico.parcels2.command
|
package io.dico.parcels2.command
|
||||||
|
|
||||||
import io.dico.dicore.command.CommandBuilder
|
import io.dico.dicore.command.CommandBuilder
|
||||||
|
import io.dico.dicore.command.ICommandAddress
|
||||||
import io.dico.dicore.command.ICommandDispatcher
|
import io.dico.dicore.command.ICommandDispatcher
|
||||||
|
import io.dico.dicore.command.predef.PredefinedCommand
|
||||||
|
import io.dico.dicore.command.registration.reflect.ReflectiveRegistration
|
||||||
import io.dico.parcels2.ParcelsPlugin
|
import io.dico.parcels2.ParcelsPlugin
|
||||||
import io.dico.parcels2.logger
|
import io.dico.parcels2.logger
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
||||||
@@ -18,7 +22,7 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
|||||||
.registerCommands(CommandsAddedStatus(plugin))
|
.registerCommands(CommandsAddedStatus(plugin))
|
||||||
|
|
||||||
.group("option")
|
.group("option")
|
||||||
.apply { CommandsParcelOptions.setGroupDescription(this) }
|
//.apply { CommandsParcelOptions.setGroupDescription(this) }
|
||||||
.registerCommands(CommandsParcelOptions(plugin))
|
.registerCommands(CommandsParcelOptions(plugin))
|
||||||
.parent()
|
.parent()
|
||||||
|
|
||||||
@@ -29,15 +33,34 @@ fun getParcelCommands(plugin: ParcelsPlugin): ICommandDispatcher {
|
|||||||
.putDebugCommands(plugin)
|
.putDebugCommands(plugin)
|
||||||
|
|
||||||
.parent()
|
.parent()
|
||||||
|
.generateHelpAndSyntaxCommands()
|
||||||
.getDispatcher()
|
.getDispatcher()
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CommandBuilder.putDebugCommands(plugin: ParcelsPlugin): CommandBuilder {
|
private fun CommandBuilder.putDebugCommands(plugin: ParcelsPlugin): CommandBuilder {
|
||||||
if (!logger.isDebugEnabled) return this
|
//if (!logger.isDebugEnabled) return this
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
return group("debug", "d")
|
return group("debug", "d")
|
||||||
.registerCommands(CommandsDebug(plugin))
|
.registerCommands(CommandsDebug(plugin))
|
||||||
.parent()
|
.parent()
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.generateHelpAndSyntaxCommands(): CommandBuilder {
|
||||||
|
generateCommands(dispatcher as ICommandAddress, "help", "syntax")
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateCommands(address: ICommandAddress, vararg names: String) {
|
||||||
|
val addresses: Queue<ICommandAddress> = LinkedList()
|
||||||
|
addresses.offer(address)
|
||||||
|
|
||||||
|
while (addresses.isNotEmpty()) {
|
||||||
|
val cur = addresses.poll()
|
||||||
|
addresses.addAll(cur.children.values.distinct())
|
||||||
|
if (cur.hasCommand()) {
|
||||||
|
ReflectiveRegistration.generateCommands(cur, names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,42 +17,39 @@ object WorldsT : Table("worlds") {
|
|||||||
val id = integer("world_id").autoIncrement().primaryKey()
|
val id = integer("world_id").autoIncrement().primaryKey()
|
||||||
val name = varchar("name", 50)
|
val name = varchar("name", 50)
|
||||||
val uid = binary("uid", 16)
|
val uid = binary("uid", 16)
|
||||||
.also { uniqueIndex("index_uid", it) }
|
val index_uid = uniqueIndexR("index_uid", uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
object ParcelsT : Table("parcels") {
|
object ParcelsT : Table("parcels") {
|
||||||
val id = integer("parcel_id").autoIncrement().primaryKey()
|
val id = integer("parcel_id").autoIncrement().primaryKey()
|
||||||
val px = integer("px")
|
val px = integer("px")
|
||||||
val pz = integer("pz")
|
val pz = integer("pz")
|
||||||
val world_id = integer("id")
|
val world_id = integer("world_id").references(WorldsT.id)
|
||||||
.also { uniqueIndex("index_location", it, px, pz) }
|
|
||||||
.references(WorldsT.id)
|
|
||||||
val owner_uuid = binary("owner_uuid", 16).nullable()
|
val owner_uuid = binary("owner_uuid", 16).nullable()
|
||||||
val owner_name = varchar("owner_name", 16).nullable()
|
val owner_name = varchar("owner_name", 16).nullable()
|
||||||
val claim_time = datetime("claim_time").nullable()
|
val claim_time = datetime("claim_time").nullable()
|
||||||
|
val index_location = uniqueIndexR("index_location", world_id, px, pz)
|
||||||
}
|
}
|
||||||
|
|
||||||
object AddedLocalT : Table("parcels_added_local") {
|
object AddedLocalT : Table("parcels_added_local") {
|
||||||
val parcel_id = integer("parcel_id")
|
val parcel_id = integer("parcel_id").references(ParcelsT.id, ReferenceOption.CASCADE)
|
||||||
.references(ParcelsT.id, ReferenceOption.CASCADE)
|
|
||||||
val player_uuid = binary("player_uuid", 16)
|
val player_uuid = binary("player_uuid", 16)
|
||||||
.also { uniqueIndex("index_pair", parcel_id, it) }
|
|
||||||
val allowed_flag = bool("allowed_flag")
|
val allowed_flag = bool("allowed_flag")
|
||||||
|
val index_pair = uniqueIndexR("index_pair", parcel_id, player_uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
object AddedGlobalT : Table("parcels_added_global") {
|
object AddedGlobalT : Table("parcels_added_global") {
|
||||||
val owner_uuid = binary("owner_uuid", 16)
|
val owner_uuid = binary("owner_uuid", 16)
|
||||||
val player_uuid = binary("player_uuid", 16)
|
val player_uuid = binary("player_uuid", 16)
|
||||||
.also { uniqueIndex("index_pair", owner_uuid, it) }
|
|
||||||
val allowed_flag = bool("allowed_flag")
|
val allowed_flag = bool("allowed_flag")
|
||||||
|
val index_pair = uniqueIndexR("index_pair", owner_uuid, player_uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
object ParcelOptionsT : Table("parcel_options") {
|
object ParcelOptionsT : Table("parcel_options") {
|
||||||
val parcel_id = integer("parcel_id")
|
val parcel_id = integer("parcel_id").references(ParcelsT.id, ReferenceOption.CASCADE)
|
||||||
.also { uniqueIndex("index_parcel_id", it) }
|
|
||||||
.references(ParcelsT.id, ReferenceOption.CASCADE)
|
|
||||||
val interact_inventory = bool("interact_inventory").default(false)
|
val interact_inventory = bool("interact_inventory").default(false)
|
||||||
val interact_inputs = bool("interact_inputs").default(false)
|
val interact_inputs = bool("interact_inputs").default(false)
|
||||||
|
val index_parcel_id = uniqueIndexR("index_parcel_id", parcel_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ExposedDatabaseException(message: String? = null) : Exception(message)
|
private class ExposedDatabaseException(message: String? = null) : Exception(message)
|
||||||
@@ -163,7 +160,6 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
rowToParcelData(row)
|
rowToParcelData(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO order by some new column
|
|
||||||
override suspend fun getOwnedParcels(user: ParcelOwner): List<SerializableParcel> = transaction {
|
override suspend fun getOwnedParcels(user: ParcelOwner): List<SerializableParcel> = transaction {
|
||||||
val where: SqlExpressionBuilder.() -> Op<Boolean>
|
val where: SqlExpressionBuilder.() -> Op<Boolean>
|
||||||
|
|
||||||
@@ -175,7 +171,8 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
where = { ParcelsT.owner_name eq name }
|
where = { ParcelsT.owner_name eq name }
|
||||||
}
|
}
|
||||||
|
|
||||||
ParcelsT.select(where).orderBy(ParcelsT.claim_time, isAsc = true)
|
ParcelsT.select(where)
|
||||||
|
.orderBy(ParcelsT.claim_time, isAsc = true)
|
||||||
.mapNotNull(::rowToSerializableParcel)
|
.mapNotNull(::rowToSerializableParcel)
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
@@ -243,7 +240,7 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
}
|
}
|
||||||
|
|
||||||
val id = getOrInitParcelId(parcelFor)
|
val id = getOrInitParcelId(parcelFor)
|
||||||
AddedLocalT.insertOrUpdate(AddedLocalT.allowed_flag) {
|
AddedLocalT.upsert(AddedLocalT.parcel_id) {
|
||||||
it[AddedLocalT.parcel_id] = id
|
it[AddedLocalT.parcel_id] = id
|
||||||
it[AddedLocalT.player_uuid] = binaryUuid
|
it[AddedLocalT.player_uuid] = binaryUuid
|
||||||
}
|
}
|
||||||
@@ -251,7 +248,7 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
|
|
||||||
override suspend fun setParcelAllowsInteractInventory(parcel: Parcel, value: Boolean): Unit = transaction {
|
override suspend fun setParcelAllowsInteractInventory(parcel: Parcel, value: Boolean): Unit = transaction {
|
||||||
val id = getOrInitParcelId(parcel)
|
val id = getOrInitParcelId(parcel)
|
||||||
ParcelOptionsT.insertOrUpdate(ParcelOptionsT.interact_inventory) {
|
ParcelOptionsT.upsert(ParcelOptionsT.parcel_id) {
|
||||||
it[ParcelOptionsT.parcel_id] = id
|
it[ParcelOptionsT.parcel_id] = id
|
||||||
it[ParcelOptionsT.interact_inventory] = value
|
it[ParcelOptionsT.interact_inventory] = value
|
||||||
}
|
}
|
||||||
@@ -259,7 +256,7 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
|
|
||||||
override suspend fun setParcelAllowsInteractInputs(parcel: Parcel, value: Boolean): Unit = transaction {
|
override suspend fun setParcelAllowsInteractInputs(parcel: Parcel, value: Boolean): Unit = transaction {
|
||||||
val id = getOrInitParcelId(parcel)
|
val id = getOrInitParcelId(parcel)
|
||||||
ParcelOptionsT.insertOrUpdate(ParcelOptionsT.interact_inputs) {
|
ParcelOptionsT.upsert(ParcelOptionsT.parcel_id) {
|
||||||
it[ParcelOptionsT.parcel_id] = id
|
it[ParcelOptionsT.parcel_id] = id
|
||||||
it[ParcelOptionsT.interact_inputs] = value
|
it[ParcelOptionsT.interact_inputs] = value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package io.dico.parcels2.storage
|
package io.dico.parcels2.storage
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.Column
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.Table
|
|
||||||
import org.jetbrains.exposed.sql.Transaction
|
|
||||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||||
|
import org.jetbrains.exposed.sql.statements.UpdateStatement
|
||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -29,8 +28,82 @@ class InsertOrUpdate<Key : Any>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null, conflictIndex: Index? = null)
|
||||||
|
: InsertStatement<Key>(table, false) {
|
||||||
|
val indexName: String
|
||||||
|
val indexColumns: List<Column<*>>
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (conflictIndex != null) {
|
||||||
|
indexName = conflictIndex.indexName
|
||||||
|
indexColumns = conflictIndex.columns
|
||||||
|
} else if (conflictColumn != null) {
|
||||||
|
indexName = conflictColumn.name
|
||||||
|
indexColumns = listOf(conflictColumn)
|
||||||
|
} else {
|
||||||
|
throw IllegalArgumentException()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun prepareSQL(transaction: Transaction): String {
|
||||||
|
val insertSQL = super.prepareSQL(transaction)
|
||||||
|
val args = arguments!!.first()
|
||||||
|
val map = mutableMapOf<Column<Any?>, Any?>().apply { args.forEach { put(it.first.castUnchecked(), it.second) } }
|
||||||
|
|
||||||
|
val updateSQL = updateBody(table, UpdateStatement(table, null, combineAsConjunctions(indexColumns.castUnchecked(), map))) {
|
||||||
|
map.forEach { col, value ->
|
||||||
|
if (col !in columns) {
|
||||||
|
it[col] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.prepareSQL(transaction)
|
||||||
|
|
||||||
|
val builder = StringBuilder().apply {
|
||||||
|
append(insertSQL)
|
||||||
|
append(" ON CONFLICT(")
|
||||||
|
append(indexName)
|
||||||
|
append(") DO UPDATE ")
|
||||||
|
append(updateSQL)
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.toString().also { println(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
|
||||||
|
inline fun <T : Table> updateBody(table: T, updateStatement: UpdateStatement,
|
||||||
|
body: T.(UpdateStatement) -> Unit): UpdateStatement {
|
||||||
|
table.body(updateStatement)
|
||||||
|
return updateStatement
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
|
||||||
|
inline fun <T> Any.castUnchecked() = this as T
|
||||||
|
|
||||||
|
private val absent = Any() // marker object
|
||||||
|
fun combineAsConjunctions(columns: Iterable<Column<Any?>>, map: Map<Column<Any?>, Any?>): Op<Boolean>? {
|
||||||
|
return with(SqlExpressionBuilder) {
|
||||||
|
columns.fold<Column<Any?>, Op<Boolean>?>(null) { op, col ->
|
||||||
|
val arg = map.getOrDefault(col, absent)
|
||||||
|
if (arg === absent) return@fold op
|
||||||
|
op?.let { it and (col eq arg) } ?: col eq arg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T : Table> T.upsert(conflictColumn: Column<*>? = null, conflictIndex: Index? = null, body: T.(UpsertStatement<Number>) -> Unit) =
|
||||||
|
UpsertStatement<Number>(this, conflictColumn, conflictIndex).apply {
|
||||||
|
body(this)
|
||||||
|
execute(TransactionManager.current())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Table.indexR(customIndexName:String? = null, isUnique: Boolean = false, vararg columns: Column<*>): Index {
|
||||||
|
val index = Index(columns.toList(), isUnique, customIndexName)
|
||||||
|
indices.add(index)
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Table.uniqueIndexR(customIndexName:String? = null, vararg columns: Column<*>): Index = indexR(customIndexName, true, *columns)
|
||||||
|
|||||||
Reference in New Issue
Block a user