diff --git a/pom.xml b/pom.xml
index 91cc830..d7e819d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,7 @@
com.scarabcoder
space-raiders
+ pom
1.0-SNAPSHOT
@@ -49,6 +50,10 @@
FastAsyncWorldEdit
http://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/
+
+ scarab-repo
+ https://mymavenrepo.com/repo/DSmbMenBusi4gORiPrHo/
+
sk89q-snapshots
@@ -70,6 +75,23 @@
+
+ com.scarabcoder
+ input-api
+ 1.0-SNAPSHOT
+
+
+ org.jetbrains.kotlinx
+ kotlinx-coroutines-core
+ 0.22.5
+
+
+
+
+ com.scarabcoder
+ command-api2
+ 1.1.6-SNAPSHOT
+
@@ -131,12 +153,6 @@
1.12.2-R0.1-SNAPSHOT
provided
-
- org.bukkit
- craftbukkit
- 1.12.2-R0.1-SNAPSHOT
- provided
-
@@ -223,6 +239,8 @@
org.jetbrains.kotlin
com.zaxxer:HikariCP
org.slf4j:slf4j-api
+ com.scarabcoder:command-api2:*
+ com.scarabcoder:input-api:*
diff --git a/src/main/kotlin/com/scarabcoder/Util.kt b/src/main/kotlin/com/scarabcoder/Util.kt
new file mode 100644
index 0000000..e864a28
--- /dev/null
+++ b/src/main/kotlin/com/scarabcoder/Util.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2018 Nicholas Harris (ScarabCoder)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.scarabcoder
+
+import com.boydti.fawe.`object`.schematic.Schematic
+import com.scarabcoder.spaceraiders.SpaceRaiders
+import com.sk89q.worldedit.Vector
+import org.bukkit.scheduler.BukkitRunnable
+
+fun async(runnable: () -> Unit) {
+ object: BukkitRunnable() {
+ override fun run() {
+ runnable()
+ }
+
+ }.runTaskAsynchronously(SpaceRaiders.getPlugin())
+}
+
+fun doLater(delay: Long, func: () -> Unit) {
+ object: BukkitRunnable() {
+ override fun run() {
+ func()
+ }
+ }.runTaskLater(SpaceRaiders.getPlugin(), delay)
+}
+
+fun Collection.nextElement(current: E): Pair {
+ if(!this.contains(current)) throw IllegalArgumentException("Collection does not contain element $current!")
+ return Pair(indexOf(current) % size, elementAt((indexOf(current) + 1) % size))
+}
+
+fun Collection.previousElement(current: E): Pair {
+ if(!this.contains(current)) throw IllegalArgumentException("Collection does not contain element $current!")
+ return Pair(indexOf(current) % size, elementAt((indexOf(current) - 1) % size))
+}
+
+fun Vector.toBukkitVector(): org.bukkit.util.Vector = org.bukkit.util.Vector(this.x, this.y, this.z)
+
+fun org.bukkit.util.Vector.fawe(): Vector = Vector(this.x, this.y, this.z)
+
+fun Vector.iterate(max: Vector): Iterator {
+ val items = ArrayList()
+ for(x in this.x.toInt()..max.x.toInt()){
+ for(y in this.y.toInt()..max.y.toInt()){
+ for(z in this.z.toInt()..max.z.toInt()){
+ items.add(Vector(x, y, z))
+ }
+ }
+ }
+ return items.iterator()
+}
+
+fun Schematic.mergeWith(other: Schematic, thisPoint: Vector = this.clipboard!!.origin, otherPoint: Vector = other.clipboard!!.origin): Schematic {
+ val schem1 = this.clipboard!!
+ val schem2 = other.clipboard!!
+
+ val offset = schem1.origin!!
+
+ for(bPos in schem2.minimumPoint.iterate(schem2.maximumPoint)){
+ val b = schem2.getBlock(bPos)
+ schem1.setBlock(bPos + offset, b)
+ }
+ return Schematic(schem1)
+}
+
+private operator fun Vector.plus(other: Vector): Vector {
+ return this.add(other)
+}
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Argument.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Argument.kt
deleted file mode 100644
index ee5cae4..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Argument.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-annotation class Argument(val name: String)
-
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParseException.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParseException.kt
deleted file mode 100644
index 329f4f8..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParseException.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-/**
- * Created by owner on 12/27/2017.
- */
-class ArgumentParseException(val name: String) : Exception()
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParser.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParser.kt
deleted file mode 100644
index 63d8171..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/ArgumentParser.kt
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-import org.bukkit.Bukkit
-import org.bukkit.entity.Player
-import java.util.function.Function
-import kotlin.reflect.KClass
-
-class ArgumentParser {
-
- private val arguments = HashMap, Function>()
-
- init {
-
- arguments.put(Int::class, Function {
- t: String -> {
- try {
- t.toInt()
- } catch(e: NumberFormatException) {
- throw ArgumentParseException("$t is not a number!")
- }
- }.invoke()
- })
- arguments.put(Double::class, Function {
- t: String -> {
- try {
- t.toDouble()
- } catch(e: NumberFormatException) {
- throw ArgumentParseException("$t is not a number!")
- }
- }.invoke()
- })
- arguments.put(Player::class, Function {
- t: String -> {
- val p: Player? = Bukkit.getPlayer(t) ?: throw ArgumentParseException("Player \"$t\" not found!")
- p
-
- }.invoke()
- })
-
-
-
- }
-
- fun registerArgument(type: KClass<*>, func: Function){
- arguments.put(type, func)
- }
-
- @Throws(ArgumentParseException::class)
- fun parse(arg:String, clazz: KClass<*>): Any? {
- if(arguments.containsKey(clazz)){
- return arguments[clazz]!!.apply(arg)
- }
- throw CommandException("Could not find a casting function for String -> " + clazz.simpleName + " (contact a developer)")
- }
-
- companion object {
- val INSTANCE = ArgumentParser()
- }
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Command.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Command.kt
deleted file mode 100644
index 4082129..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Command.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-annotation class Command
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandException.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandException.kt
deleted file mode 100644
index 3496b06..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandException.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-/**
- * Created by owner on 12/27/2017.
- */
-class CommandException(val name: String) : Exception()
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandHandler.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandHandler.kt
deleted file mode 100644
index 92b31ba..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandHandler.kt
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-import com.scarabcoder.gamecore.messaging.Message
-import com.scarabcoder.gamecore.messaging.Messages
-import org.apache.commons.lang.StringUtils
-import org.bukkit.entity.Player
-import kotlin.reflect.KClass
-import kotlin.reflect.KParameter
-
-class CommandHandler {
-
-
- internal fun execute(sender: Player, cmd: String, args: List) {
- val section = CommandRegistry.getSection(cmd)!!
- for (set in CommandRegistry.getTree(section)) {
- if (StringUtils.join(args, " ").startsWith(set.key)) {
- val modifiedArgs: MutableList = args.subList(if (StringUtils.split(set.key, ' ').isNotEmpty()) StringUtils.split(set.key, ' ').size else 0, args.size).toMutableList()
- if (modifiedArgs.size > 0) {
- for (method in set.value::class.members) {
- val hasAn = method.annotations.any { it.annotationClass == Command::class }
-
- if (hasAn && method.name == modifiedArgs[0]) {
- modifiedArgs.removeAt(0)
- val toPass: MutableList = ArrayList()
- toPass.addAll(modifiedArgs)
- toPass.add(0, sender)
- var x = 0
- val newParams: MutableList = method.parameters.toMutableList()
- newParams.removeAt(0)
-
- for (param in newParams) {
- if (toPass.size == x)
- break
- if (x == 0) {
- x++
- continue
- }
- if (param.type != toPass[x]::class) {
- try {
- toPass[x] = ArgumentParser.INSTANCE.parse(toPass[x] as String, param.type.classifier as KClass<*>) as Any
-
- } catch(exc: ArgumentParseException) {
- sender.sendMessage(Messages.msg(Message.TYPE_ARGUMENT_CAST_ERROR, getParamName(param), exc.name))
- return
- } catch(exc: CommandException) {
- sender.sendMessage(exc.name)
- exc.printStackTrace()
- return
- }
-
- }
- x++
- }
- newParams.add(0, method.parameters[0])
- if (method.parameters.size - 2 == modifiedArgs.size) {
- method.call(set.value, *toPass.toTypedArray())
- return
- } else {
- var params = ""
- val requiredParams = method.parameters.toMutableList()
- requiredParams.removeAt(0)
- requiredParams.removeAt(0)
- for (param in requiredParams) {
- params += "<${getParamName(param)}> "
- }
- sender.sendMessage(Messages.msg(Message.INVALID_USAGE, "/${set.key} ${method.name} $params"))
- return
- }
-
- }
- }
- } else {
- section.onCommand(sender)
- }
- return
- }
- sender.sendMessage(Messages.msg(Message.UNKNOWN_COMMAND))
- }
- }
-
- private fun getParamName(p: KParameter): String {
- for (a in p.annotations) {
- println(a::class)
- println(Argument::class)
- if (a::class == Argument::class) {
- val arg = a as Argument
- return arg.name
- }
- }
- return p.name!!
- }
-
- companion object {
- val INSTANCE = CommandHandler()
- }
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandRegistry.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandRegistry.kt
deleted file mode 100644
index f66f2a3..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandRegistry.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-import com.scarabcoder.spaceraiders.SpaceRaiders
-import org.bukkit.Bukkit
-import org.bukkit.command.Command
-import org.bukkit.command.CommandMap
-import org.bukkit.command.CommandSender
-import org.bukkit.entity.Player
-import java.lang.reflect.Field
-import java.util.*
-import java.util.logging.Level
-
-object CommandRegistry {
-
- var cmds: HashMap = HashMap()
-
- fun registerCommand(section: CommandSection){
- cmds.put(section.name, section)
-
- val cmdMap: Field = Bukkit.getServer().javaClass.getDeclaredField("commandMap")
- cmdMap.isAccessible = true
-
- val serverCmds: CommandMap = cmdMap.get(Bukkit.getServer()) as CommandMap
- serverCmds.register(section.name, BukkitCommand(section))
-
- SpaceRaiders.getLogger().log(Level.INFO, "Registered command " + section.name)
- }
-
- internal fun getTree(root: CommandSection): HashMap {
- var children = HashMap()
- for((key, section) in root.getChildren()){
- children.put("${root.name} $key", section)
- }
- children.put(root.name, root)
- return children
- }
-
-
- internal fun getSection(section: String): CommandSection? {
- return cmds[section]
- }
-
- class BukkitCommand(val section: CommandSection) : Command(section.name, section.description(), section.usage(), section.aliases()) {
-
- override fun execute(sender: CommandSender?, p1: String?, argsArr: Array?): Boolean {
-
- val args : MutableList = argsArr!!.toMutableList()
- args.add(0, section.name)
-
- if(sender is Player){
- CommandHandler.INSTANCE.execute(sender, section.name, args)
- }
- return true
- }
-
- }
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandSection.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandSection.kt
deleted file mode 100644
index a1484d4..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/CommandSection.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-import org.bukkit.entity.Player
-import java.util.*
-import kotlin.collections.HashMap
-
-open class CommandSection(val name:String) {
-
- val sections: MutableList = ArrayList()
-
- fun section(section: CommandSection): CommandSection {
- sections.add(section)
- Logger.logger.log("$name registered command section " + section.name, Logger.Level.INFO)
- return this
- }
-
- internal fun getChildren(): HashMap {
- var children: HashMap = HashMap();
- for(sec in sections){
- children.put(sec.name, sec)
- for((key, v) in sec.getChildren()){
- children.put("$key ${sec.name}", v)
- }
- }
- return children
- }
-
- open fun onCommand(player: Player) {
-
- }
-
- open fun aliases(): MutableList {
- return ArrayList();
- }
-
- open fun description(): String {
- return ""
- }
-
- open fun usage(): String {
- return ""
- }
-
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Logger.kt b/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Logger.kt
deleted file mode 100644
index ecf8f84..0000000
--- a/src/main/kotlin/com/scarabcoder/gamecore/commandapi/Logger.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-package com.scarabcoder.gamecore.commandapi
-
-import com.scarabcoder.spaceraiders.SpaceRaiders
-
-class Logger {
-
- private val prefix = "SpaceRaiders";
-
- fun log(msg:String, level: Level){
- if(!(level == Level.DEBUG && SpaceRaiders.getPlugin().config.getBoolean("debug"))){
- System.out.println("[$prefix] [$level] $msg")
- }
- }
-
-
- companion object {
- var logger: Logger = Logger();
- }
-
- enum class Level {
- INFO, WARNING, ERROR, DEBUG
- }
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/messaging/Message.kt b/src/main/kotlin/com/scarabcoder/gamecore/messaging/Message.kt
index 294d688..0a81bff 100644
--- a/src/main/kotlin/com/scarabcoder/gamecore/messaging/Message.kt
+++ b/src/main/kotlin/com/scarabcoder/gamecore/messaging/Message.kt
@@ -21,7 +21,15 @@ enum class Message(val msg: String, vararg val placeholders: String) {
UNKNOWN_COMMAND("${ChatColor.RED}Command not found!"),
TYPE_ARGUMENT_CAST_ERROR("${ChatColor.RED}Error with argument %a: %e", "a", "p"),
- INVALID_USAGE("${ChatColor.RED}Invalid command usage. Usage: %p", "p");
+ INVALID_USAGE("${ChatColor.RED}Invalid command usage. Usage: %p", "p"),
+ IN_BATTLE_ERROR("${ChatColor.RED}You cannot teleport while in battle!"),
+ IN_SHIP_STATE_ERROR("${ChatColor.RED}You cannot use this command while %s", "s"),
+ TELEPORTING_TO("${ChatColor.GREEN}Teleporting to %l...", "l"),
+ NOT_IN_REQ_STATE("${ChatColor.RED}You must be %s to use this command!", "s"),
+ SHIP_BEING_EDITED("${ChatColor.RED}That ship is already being edited by %p", "p"),
+ CROUCH_AGAIN_TO_LEAVE("${ChatColor.GOLD}Press shift again to stop editing the ship."),
+ EDITING_PART("${ChatColor.AQUA}Editing part %p", "p");
+
fun getConfigPath(): String {
return this.name.toLowerCase().replace("_", "-")
diff --git a/src/main/kotlin/com/scarabcoder/gamecore/sql/Connections.kt b/src/main/kotlin/com/scarabcoder/gamecore/sql/Connections.kt
index b8d7253..422fe5b 100644
--- a/src/main/kotlin/com/scarabcoder/gamecore/sql/Connections.kt
+++ b/src/main/kotlin/com/scarabcoder/gamecore/sql/Connections.kt
@@ -41,8 +41,6 @@ object Connections {
hcf.minimumIdle = 3
dataSource = HikariDataSource(hcf)
}
-
-
}
fun grabConnection(): Connection {
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/SpaceRaiders.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/SpaceRaiders.kt
index ececf2d..e4970f3 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/SpaceRaiders.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/SpaceRaiders.kt
@@ -16,8 +16,9 @@
package com.scarabcoder.spaceraiders
import com.comphenix.protocol.ProtocolLibrary
-import com.scarabcoder.gamecore.commandapi.CommandRegistry
+import com.scarabcoder.commandapi2.CommandRegistry
import com.scarabcoder.gamecore.sql.Connections
+import com.scarabcoder.input.InputManager
import com.scarabcoder.spaceraiders.command.SpaceRaidersCommand
import com.scarabcoder.spaceraiders.data.DataManager
import org.bukkit.Bukkit
@@ -32,28 +33,28 @@ class SpaceRaiders : JavaPlugin(){
config.options().copyDefaults(true)
saveDefaultConfig()
- SpaceRaiders.log = logger
- val protocolManager = ProtocolLibrary.getProtocolManager()
- CommandRegistry.registerCommand(SpaceRaidersCommand("spaceraiders"))
+ CommandRegistry.registerCommand(SpaceRaidersCommand())
+ InputManager.thisPlugin = this
Connections.grabConnection().close()
DataManager.createTables()
DataManager.load()
+ registerValidators()
+
}
+
+
companion object {
+ val logger: Logger
+ get() = getPlugin().logger
+
fun getPlugin(): Plugin {
return Bukkit.getPluginManager().getPlugin("SpaceRaiders")
}
-
- private var log: Logger? = null
-
- fun getLogger():Logger {
- return log!!
- }
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/Validators.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/Validators.kt
new file mode 100644
index 0000000..359797b
--- /dev/null
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/Validators.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018 Nicholas Harris (ScarabCoder)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.scarabcoder.spaceraiders
+
+import com.scarabcoder.commandapi2.CommandValidator
+import com.scarabcoder.gamecore.messaging.Message
+import com.scarabcoder.gamecore.messaging.Messages
+import com.scarabcoder.spaceraiders.data.DataManager
+import com.scarabcoder.spaceraiders.player.SRPlayer
+import com.scarabcoder.spaceraiders.ship.Ship
+
+object NotInActiveState: CommandValidator {
+ override fun validate(sender: SRPlayer): Boolean {
+ if(sender.currentShipState != null){
+ sender.sendMessage(Messages.msg(Message.IN_SHIP_STATE_ERROR, sender.currentShipState!!.readableName.toLowerCase()))
+ return false
+ }
+ return true
+ }
+}
+
+object InHangarValidator: CommandValidator {
+
+ override fun validate(sender: SRPlayer): Boolean {
+ if(sender.currentShipState != null && sender.currentShipState!!.stateType == Ship.State.HANGAR) return true
+ sender.sendMessage(Messages.msg(Message.NOT_IN_REQ_STATE, "in hangar"))
+ return false
+ }
+}
+
+fun registerValidators(){
+ CommandValidator.registerValidator(NotInActiveState)
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/command/HangarCommand.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/command/HangarCommand.kt
new file mode 100644
index 0000000..7018709
--- /dev/null
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/command/HangarCommand.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018 Nicholas Harris (ScarabCoder)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.scarabcoder.spaceraiders.command
+import com.scarabcoder.commandapi2.Command
+import com.scarabcoder.commandapi2.CommandSection
+import com.scarabcoder.gamecore.messaging.Message
+import com.scarabcoder.gamecore.messaging.Messages
+import com.scarabcoder.spaceraiders.InHangarValidator
+import com.scarabcoder.spaceraiders.NotInActiveState
+import com.scarabcoder.spaceraiders.player.SRPlayer
+import java.util.*
+
+class HangarCommand: CommandSection("hangar") {
+
+ override val aliases: MutableList = Arrays.asList("h", "hg")
+
+ @Command(aliases = ["h"], validators = [NotInActiveState::class])
+ fun home(sender: SRPlayer) {
+ sender.sendMessage(Messages.msg(Message.TELEPORTING_TO, "your private hangar"))
+ sender.player.teleport(sender.privateHangar.center)
+ }
+
+ @Command(aliases = ["l"], validators = [InHangarValidator::class])
+ fun leave(sender: SRPlayer) {
+ sender.currentShipState!!.removeMember(sender)
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/command/SpaceRaidersCommand.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/command/SpaceRaidersCommand.kt
index 4027811..5da7906 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/command/SpaceRaidersCommand.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/command/SpaceRaidersCommand.kt
@@ -18,24 +18,24 @@ package com.scarabcoder.spaceraiders.command
import com.comphenix.protocol.PacketType
import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.events.PacketContainer
-import com.scarabcoder.gamecore.commandapi.Command
-import com.scarabcoder.gamecore.commandapi.CommandSection
+import com.scarabcoder.commandapi2.Command
+import com.scarabcoder.commandapi2.CommandSection
import org.bukkit.entity.Player
import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntityLiving
import net.minecraft.server.v1_12_R1.EntityArmorStand
import com.scarabcoder.gamecore.sql.Connections
+import org.bukkit.command.CommandSender
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld
-
+import java.util.*
/**
* Created by owner on 1/3/2018.
*/
-class SpaceRaidersCommand(name: String): CommandSection(name) {
+class SpaceRaidersCommand: CommandSection("spaceraiders") {
- override fun onCommand(player: Player) {
+ override val aliases: MutableList = Arrays.asList("sr")
- }
@Command
fun mytest(sender: Player){
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/data/DataManager.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/data/DataManager.kt
index 93a1c98..08e6646 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/data/DataManager.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/data/DataManager.kt
@@ -15,6 +15,8 @@
package com.scarabcoder.spaceraiders.data
+import com.google.common.collect.ImmutableList
+import com.google.common.collect.ImmutableMap
import com.scarabcoder.gamecore.sql.Connections
import com.scarabcoder.spaceraiders.SpaceRaiders
import com.scarabcoder.spaceraiders.player.SRPlayer
@@ -51,6 +53,11 @@ object DataManager: Listener{
private val hangars: HashMap = HashMap()
private val planets: HashMap = HashMap()
+ val activeShips: List
+ get() = ships.values.toList()
+ val autoGeneratedHangars: List
+ get() = hangars.values.filter { it.autoGenerated }
+
init {
Bukkit.getPluginManager().registerEvents(this, SpaceRaiders.getPlugin())
}
@@ -124,7 +131,7 @@ object DataManager: Listener{
val rs = ps.executeQuery()
if(rs.next()){
val planet = planets[rs.getInt("planet")]!!
- if(!planet.isLoaded())
+ if(!planet.isLoaded)
planet.loadWorld()
val center = Location(planet.world!!, rs.getInt("x").toDouble(),
rs.getInt("y").toDouble(),
@@ -143,6 +150,20 @@ object DataManager: Listener{
return null
}
+ private fun createPlayer(player: OfflinePlayer): SRPlayer {
+ val c = Connections.grabConnection()
+ c.use { c ->
+ val ps = c.prepareStatement("INSERT INTO players (uuid, username, squad) VALUES (?, ?, NULL);")
+ ps.setString(1, player.uniqueId.toString())
+ ps.setString(2, player.name)
+ ps.executeUpdate()
+ }
+ val pl = SRPlayer(player.uniqueId, player.name, null)
+ players.put(pl.uuid, pl)
+ Hangar.autoGenerate(pl, Hangar.Size.SMALL)
+ return pl
+ }
+
fun loadHangarsAndShips(planet: Planet) {
val c = Connections.grabConnection()
try {
@@ -230,21 +251,6 @@ object DataManager: Listener{
return null
}
- private fun createPlayer(player: OfflinePlayer): SRPlayer {
- val c = Connections.grabConnection()
- try {
- val ps = c.prepareStatement("INSERT INTO players (uuid, username, squad) VALUES (?, ?, NULL);")
- ps.setString(1, player.uniqueId.toString())
- ps.setString(2, player.name)
- ps.executeUpdate()
- } finally {
- c.close()
- }
- val pl = SRPlayer(player.uniqueId, player.name, null)
- players.put(pl.uuid, pl)
- return pl
- }
-
fun getPlayer(uuid: UUID): SRPlayer {
if(players.containsKey(uuid)) return players[uuid]!!
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/player/SRPlayer.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/player/SRPlayer.kt
index 5c598b4..ecf7b67 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/player/SRPlayer.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/player/SRPlayer.kt
@@ -17,7 +17,12 @@ package com.scarabcoder.spaceraiders.player
import com.scarabcoder.spaceraiders.data.DataManager
+import com.scarabcoder.spaceraiders.ship.Hangar
+import com.scarabcoder.spaceraiders.ship.state.ShipState
+import net.md_5.bungee.api.ChatMessageType
+import net.md_5.bungee.api.chat.TextComponent
import org.bukkit.Bukkit
+import org.bukkit.Location
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import java.util.*
@@ -25,27 +30,37 @@ import java.util.*
/**
* Created by owner on 1/5/2018.
*/
-class SRPlayer(val uuid: UUID, var username: String, var squad: Int?) {
+class SRPlayer(val uuid: UUID, var username: String, var squadID: Int?) {
var cached = false
var cachedTime = System.currentTimeMillis()
+ val isOnline: Boolean
+ get() = Bukkit.getPlayer(uuid) == null
+ val offlinePlayer: OfflinePlayer
+ get() = Bukkit.getOfflinePlayer(uuid)
- fun isOnline(): Boolean{
- return getPlayer() != null
- }
+ val player: Player
+ get() = Bukkit.getPlayer(uuid)
- fun getOfflinePlayer(): OfflinePlayer {
- return Bukkit.getOfflinePlayer(uuid)
- }
+ val squad: Squad?
+ get() = if(squadID == null) null else DataManager.getSquad(squadID!!)
- fun getPlayer(): Player {
- return Bukkit.getPlayer(uuid)
- }
+ val privateHangar: Hangar
+ get() = DataManager.autoGeneratedHangars.first { it.owner == uuid }
+
+ var currentShipState: ShipState? = null
+ get() = DataManager.activeShips.find { it.state.members.contains(this) }?.state
+
+ var preStateLocation: Location = player.location
+
+ fun sendMessage(message: String) = player.spigot().sendMessage(*TextComponent.fromLegacyText(message))
+
+ fun sendActionBar(message: String) = player.spigot().sendMessage(ChatMessageType.ACTION_BAR, *TextComponent.fromLegacyText(message))
- fun getSquad(): Squad? {
- return if(squad == null) null else DataManager.getSquad(squad!!)
+ override fun hashCode(): Int {
+ return uuid.hashCode()
}
companion object {
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hangar.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hangar.kt
index 23b8bec..68ec2db 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hangar.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hangar.kt
@@ -27,6 +27,8 @@ import com.scarabcoder.spaceraiders.data.DataManager
import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.world.DefaultWorlds
import com.scarabcoder.spaceraiders.world.Planet
+import com.scarabcoder.toBukkitVector
+import com.sk89q.worldedit.bukkit.BukkitUtil
import org.bukkit.Location
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
@@ -37,7 +39,12 @@ import java.util.*
/**
* Created by owner on 1/5/2018.
*/
-class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID, val shipID: Int, val autoGenerated: Boolean, val planet: Planet?) {
+class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID, val shipID: Int, val autoGenerated: Boolean, val planet: Planet?, private val editingOffset: Vector) {
+
+ val editingLocation: Location
+ get() {
+ return center.add(editingOffset.toBukkitVector())
+ }
init {
size.getSchematic().paste(BukkitWorld(center.world), Vector(center.blockX, center.blockY, center.blockZ), false, true, null)
@@ -46,6 +53,8 @@ class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID,
val ship: Ship by lazy {
DataManager.getShip(shipID)!!
}
+ val shipCenter: Location
+ get() = center.add(org.bukkit.util.Vector(0, 4, 0))
companion object {
@@ -100,7 +109,7 @@ class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID,
ps.setString(9, player.uuid.toString())
ps.executeUpdate()
- val hangar = Hangar(hangarID, loc, size, player.uuid, shipID, autoGenerated, planet)
+ val hangar = Hangar(hangarID, loc, size, player.uuid, shipID, autoGenerated, planet, size.editingLocation)
DataManager.addToCache(hangar)
ps = c.prepareStatement("INSERT INTO ships (id, owner, engine, hull) VALUES (?, ?, ?, ?)")
@@ -117,7 +126,7 @@ class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID,
}else {
size.getSchematic().paste(BukkitWorld(loc.world), Vector(loc.x, loc.y, loc.z), false, true, null)
}
- ship.buildSchematic()!!.paste(BukkitWorld(loc.world), Vector(loc.x, loc.y + 8, loc.z), false, false, null) //TODO: Fine tune the positioning
+ ship.buildSchematic()!!.paste(BukkitWorld(loc.world), Vector(loc.x, loc.y + 4, loc.z), false, false, null) //TODO: Fine tune the positioning
return hangar
@@ -146,9 +155,9 @@ class Hangar(val id: Int, val center: Location, val size: Size, val owner: UUID,
}
}
- enum class Size(val sizeName: String) {
+ enum class Size(val sizeName: String, val editingLocation: Vector) {
- SMALL("Scout"), MEDIUM("Fighter"), LARGE("Destroyer");
+ SMALL("Scout", Vector(0,0,0)), MEDIUM("Fighter", Vector(0,0,0)), LARGE("Destroyer", Vector(0,0,0));
override fun toString(): String {
return sizeName
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hull.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hull.kt
index 1b63eec..2c9fb34 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hull.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Hull.kt
@@ -17,7 +17,6 @@ package com.scarabcoder.spaceraiders.ship
import com.boydti.fawe.`object`.schematic.Schematic
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat
-import com.scarabcoder.gamecore.commandapi.Logger
import com.scarabcoder.spaceraiders.SpaceRaiders
import com.scarabcoder.spaceraiders.data.DataFolders
import org.bukkit.configuration.InvalidConfigurationException
@@ -28,7 +27,7 @@ import java.io.FileNotFoundException
import java.util.logging.Level
import java.util.stream.Collectors
-data class Hull(val nameID: String, val displayName: String, val turretLocations: List, val engineOne: Vector, val engineTwo: Vector){
+data class Hull(val nameID: String, val displayName: String, val turretLocations: List, val engineOne: Vector, val engineTwo: Vector, val screen: Pair, val chair: Vector){
val schematic: Schematic = ClipboardFormat.SCHEMATIC.load(File(DataFolders.hulls, "${nameID}.schematic"))
@@ -61,7 +60,12 @@ data class Hull(val nameID: String, val displayName: String, val turretLocations
fc.getStringList("turret-locations")
.map { it.split(",") }
.mapTo(turretLocations) { Vector(it[0].toInt(), it[1].toInt(), it[2].toInt()) }
- return Hull(file.nameWithoutExtension, fc.getString("display-name"), turretLocations, fc.getVector("engine-one"), fc.getVector("engine-two"))
+ return Hull(file.nameWithoutExtension,
+ fc.getString("display-name"),
+ turretLocations,
+ fc.getVector("engine-one"), fc.getVector("engine-two"),
+ Pair(fc.getVector("screen-1"), fc.getVector("screen-2")),
+ fc.getVector("chair"))
}
fun getDefault(size: Hangar.Size): Hull{
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Ship.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Ship.kt
index e0a5e35..4acaa84 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Ship.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/Ship.kt
@@ -16,9 +16,13 @@
package com.scarabcoder.spaceraiders.ship
import com.boydti.fawe.`object`.schematic.Schematic
+import com.scarabcoder.fawe
+import com.scarabcoder.iterate
+import com.scarabcoder.mergeWith
import com.scarabcoder.spaceraiders.data.DataFolders
import com.scarabcoder.spaceraiders.data.DataManager
import com.scarabcoder.spaceraiders.ship.state.*
+import com.sk89q.worldedit.Vector
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File
import java.util.*
@@ -28,7 +32,7 @@ import kotlin.collections.HashMap
* Created by owner on 1/5/2018.
*/
-class Ship(val id: Int, val hangar: Hangar, val size: Hangar.Size, val owner: UUID, var name: String?, val hull: Hull, val engine: Engine) {
+class Ship(val id: Int, val hangar: Hangar, val size: Hangar.Size, val owner: UUID, var name: String?, var hull: Hull, var engine: Engine) {
val partData = File(DataFolders.ships, id.toString())
val engineFolder = File(partData, "engine")
@@ -37,16 +41,19 @@ class Ship(val id: Int, val hangar: Hangar, val size: Hangar.Size, val owner: UU
val engineData: HashMap = HashMap()
val hullData: HashMap = HashMap()
- var state: ShipState = HangarState(this)
+ var state: ShipState = HangarState(this, Collections.emptyList())
+ set(value) {
+ field.onSwitch()
+ field = value
+ }
val stateType: State
- get() {
- if(state is HangarState) return State.HANGAR
- if(state is BattleState) return State.BATTLE
- if(state is TravelState) return State.TRAVEL
- if(state is PlanetState) return State.PLANET
- throw IllegalStateException("The state was not set correctly!")
- }
+ get() = state.stateType
+
+ val unlockedHulls: List
+ get() = hullData.filter {it.value.unlocked}.map { it.key }
+ val unlockedEngines: List
+ get() = engineData.filter {it.value.unlocked}.map { it.key }
init {
@@ -81,9 +88,20 @@ class Ship(val id: Int, val hangar: Hangar, val size: Hangar.Size, val owner: UU
}
- fun buildSchematic(): Schematic? {
- //TODO: Will build the hull along with both engines, using the connection points defined as vectors for each point
- return null
+ fun buildSchematic(): Schematic {
+
+ val hullC = hull.schematic.clipboard!!
+ val engineC = engine.schematic.clipboard!!
+
+ var combine1 = hull.schematic.mergeWith(engine.schematic, hull.engineOne.fawe(), engine.hullLink.fawe())
+ val cclip = combine1.clipboard!!
+ val offset = cclip.origin.add(hull.engineTwo.fawe())
+ for(bPos in cclip.minimumPoint.iterate(cclip.maximumPoint)){
+ val b = cclip.getBlock(bPos)
+ cclip.setBlock(bPos.setX(cclip.maximumPoint.x - bPos.x), b)
+ }
+ combine1 = Schematic(cclip)
+ return combine1
}
fun savePartsData(){
@@ -148,4 +166,7 @@ class Ship(val id: Int, val hangar: Hangar, val size: Hangar.Size, val owner: UU
HANGAR, TRAVEL, BATTLE, PLANET
}
-}
\ No newline at end of file
+ enum class PartType { HULL, ENGINE }
+
+}
+
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/BattleState.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/BattleState.kt
index 70726fc..31e4d96 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/BattleState.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/BattleState.kt
@@ -15,10 +15,11 @@
package com.scarabcoder.spaceraiders.ship.state
+import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.ship.Ship
-class BattleState(ship: Ship, val enemy: Ship): ShipState(ship) {
-
+class BattleState(ship: Ship, val enemy: Ship, members: MutableList): ShipState(ship, members, "In Battle") {
+ override val stateType = Ship.State.BATTLE
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/HangarState.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/HangarState.kt
index b4fc1cf..bdbf919 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/HangarState.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/HangarState.kt
@@ -15,7 +15,102 @@
package com.scarabcoder.spaceraiders.ship.state
+import com.scarabcoder.doLater
+import com.scarabcoder.gamecore.messaging.Message
+import com.scarabcoder.gamecore.messaging.Messages
+import com.scarabcoder.input.InputManager
+import com.scarabcoder.input.InputType
+import com.scarabcoder.input.PlayerInputEvent
+import com.scarabcoder.nextElement
+import com.scarabcoder.previousElement
+import com.scarabcoder.spaceraiders.SpaceRaiders
+import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.ship.Ship
+import com.sk89q.worldedit.Vector
+import com.sk89q.worldedit.bukkit.BukkitWorld
+import org.bukkit.Bukkit
+import org.bukkit.ChatColor
+import org.bukkit.event.EventHandler
+import org.bukkit.event.HandlerList
+import org.bukkit.event.Listener
+
+class HangarState(ship: Ship, members: MutableList): ShipState(ship, members, "In Hangar"), Listener {
+
+ init {
+ Bukkit.getPluginManager().registerEvents(this, SpaceRaiders.getPlugin())
+ }
+
+ private var leaveNextCrouch = false
+
+ private var editingPart = Ship.PartType.HULL
+ set(value) {
+ if(members.isNotEmpty()){
+ members[0].sendActionBar(Messages.msg(Message.EDITING_PART, value.name.toLowerCase().capitalize()))
+ field = value
+ }
+ }
+
+ @EventHandler
+ private fun playerInputEvent(e: PlayerInputEvent){
+ if(e.isKeyUp) return
+ val p = SRPlayer.from(e.player)
+ if(e.key == InputType.W || e.key == InputType.S){
+ editingPart = if(editingPart == Ship.PartType.HULL) Ship.PartType.ENGINE else Ship.PartType.HULL
+ p.sendMessage(Messages.msg(Message.EDITING_PART, editingPart.name.toLowerCase().capitalize()))
+ return
+ }
+ if(e.key == InputType.D || e.key == InputType.A){
+ if(editingPart == Ship.PartType.HULL){
+ val (_, next) = if(e.key == InputType.D) ship.unlockedHulls.nextElement(ship.hull) else ship.unlockedHulls.previousElement(ship.hull)
+ ship.hull = next
+ p.sendActionBar("${ChatColor.GREEN}${next.displayName}")
+ } else {
+ val (_, next) = if(e.key == InputType.D) ship.unlockedEngines.nextElement(ship.engine) else ship.unlockedEngines.previousElement(ship.engine)
+ ship.engine = next
+ p.sendActionBar("${ChatColor.GREEN}${next.displayName}")
+ }
+ val l = ship.hangar.shipCenter
+ ship.buildSchematic().paste(BukkitWorld(l.world), Vector(l.x, l.y, l.z))
+ return
+ }
+ if(e.key == InputType.SHIFT){
+ if(leaveNextCrouch){
+ removeMember(members[0])
+ return
+ }
+ leaveNextCrouch = true
+ p.sendMessage(Messages.msg(Message.CROUCH_AGAIN_TO_LEAVE))
+ doLater(5 * 20) { leaveNextCrouch = false }
+ return
+ }
+ //TODO Open GUI on Spacebar
+
+
+ }
+
+ override val stateType = Ship.State.HANGAR
+
+ override fun removeMember(player: SRPlayer) {
+ InputManager.detach(player.player)
+ player.player.teleport(player.preStateLocation)
+ return super.removeMember(player)
+ }
+
+ override fun addMember(player: SRPlayer) {
+
+ if(members.isEmpty()) {
+ player.player.teleport(ship.hangar.editingLocation)
+ InputManager.attach(player.player)
+ }else {
+ player.sendMessage(Messages.msg(Message.SHIP_BEING_EDITED, members[0].username))
+ return
+ }
+ return super.addMember(player)
+ }
+
+ override fun onSwitch() {
+ HandlerList.unregisterAll(this)
+ super.onSwitch()
+ }
-class HangarState(ship: Ship): ShipState(ship) {
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/PlanetState.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/PlanetState.kt
index 176e8e2..dcf1b67 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/PlanetState.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/PlanetState.kt
@@ -15,7 +15,10 @@
package com.scarabcoder.spaceraiders.ship.state
+import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.ship.Ship
+import com.scarabcoder.spaceraiders.world.Planet
-class PlanetState(ship: Ship): ShipState(ship) {
+class PlanetState(ship: Ship, val planet: Planet, members: MutableList): ShipState(ship, members, "On Planet") {
+ override val stateType = Ship.State.PLANET
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/ShipState.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/ShipState.kt
index 90a7d6b..2aa1b11 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/ShipState.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/ShipState.kt
@@ -18,8 +18,33 @@ package com.scarabcoder.spaceraiders.ship.state
import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.ship.Ship
-open class ShipState(val ship: Ship) {
+abstract class ShipState(val ship: Ship, members: List, val readableName: String) {
+
+
+ private val _members: MutableList = members.toMutableList()
+ init {
+ //Run the addMember() function for players this state have been initialized with, so that sub-states that override the function can handle players joining a state.
+ members.forEach { addMember(it) }
+ }
+
+ val members = _members as List
+
+ open fun addMember(player: SRPlayer) {
+ _members.add(player)
+ }
+ open fun removeMember(player: SRPlayer) {
+ _members.remove(player)
+ }
+
+ init {
+ members.forEach { it.preStateLocation = it.player.location }
+ }
+
+ abstract val stateType: Ship.State
+
+ open fun onSwitch() {
+ members.forEach { removeMember(it) }
+ }
- val members: MutableList = ArrayList()
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/TravelState.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/TravelState.kt
index 0cc64c1..9fc8dc9 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/TravelState.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/ship/state/TravelState.kt
@@ -15,10 +15,12 @@
package com.scarabcoder.spaceraiders.ship.state
+import com.scarabcoder.spaceraiders.player.SRPlayer
import com.scarabcoder.spaceraiders.ship.Ship
import com.scarabcoder.spaceraiders.world.SpaceLocation
-class TravelState(ship: Ship, var location: SpaceLocation): ShipState(ship) {
+class TravelState(ship: Ship, var location: SpaceLocation, members: MutableList): ShipState(ship, members, "Traveling") {
+ override val stateType = Ship.State.TRAVEL
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/world/BlankWorldManager.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/world/BlankWorldManager.kt
new file mode 100644
index 0000000..c40a189
--- /dev/null
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/world/BlankWorldManager.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2018 Nicholas Harris (ScarabCoder)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package com.scarabcoder.spaceraiders.world
+
+import com.scarabcoder.async
+import com.scarabcoder.spaceraiders.SpaceRaiders
+import org.apache.commons.io.FileUtils
+import org.bukkit.Bukkit
+import org.bukkit.World
+import org.bukkit.WorldCreator
+import org.bukkit.WorldType
+import org.bukkit.scheduler.BukkitRunnable
+import java.util.*
+
+object BlankWorldManager {
+
+ init {
+ object: BukkitRunnable() {
+ override fun run() {
+ for(world in worlds){
+ if(world.players.size == 0){
+ Bukkit.unloadWorld(world, false)
+ async {
+ FileUtils.deleteDirectory(world.worldFolder)
+ }
+ }
+ }
+ }
+ }.runTaskTimer(SpaceRaiders.getPlugin(), 60 * 20, 60 * 20)
+ }
+
+ private val worlds = ArrayList()
+
+ fun generateEmpty(): World {
+ val wc = WorldCreator("temp-${UUID.randomUUID()}")
+ wc.type(WorldType.FLAT)
+ wc.generatorSettings("2;0;1;")
+ return wc.createWorld().also { worlds.add(it) }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/world/DefaultWorlds.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/world/DefaultWorlds.kt
index 11824fb..84f5043 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/world/DefaultWorlds.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/world/DefaultWorlds.kt
@@ -15,35 +15,18 @@
package com.scarabcoder.spaceraiders.world
+import net.minecraft.server.v1_12_R1.WorldServer
import org.bukkit.Bukkit
import org.bukkit.World
import org.bukkit.WorldCreator
import org.bukkit.WorldType
+import org.bukkit.craftbukkit.v1_12_R1.CraftChunk
+import org.bukkit.craftbukkit.v1_12_R1.CraftServer
+import org.bukkit.craftbukkit.v1_12_R1.CraftWorld
+import org.bukkit.event.EventHandler
+import org.bukkit.event.world.ChunkLoadEvent
import sun.plugin.dom.exception.InvalidAccessException
-/*
- * The MIT License
- *
- * Copyright 2018 Nova Pixel Network
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
enum class DefaultWorlds(val worldName: String) {
AUTOGEN_HANGARS("generatedhangars");
@@ -63,6 +46,16 @@ enum class DefaultWorlds(val worldName: String) {
val wc = WorldCreator(worldName)
wc.type(WorldType.FLAT)
wc.generatorSettings("2;0;1;")
+
return wc.createWorld()
}
+
+ @EventHandler
+ fun chunkLoadEvent(e: ChunkLoadEvent) {
+ val clazz = CraftWorld::class.java
+ val f = clazz.getField("world")
+ f.isAccessible = true
+ val ws = f.get(e.world) as WorldServer
+ //ws.playerChunkMap.
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/scarabcoder/spaceraiders/world/Planet.kt b/src/main/kotlin/com/scarabcoder/spaceraiders/world/Planet.kt
index 6258638..09ec0e9 100644
--- a/src/main/kotlin/com/scarabcoder/spaceraiders/world/Planet.kt
+++ b/src/main/kotlin/com/scarabcoder/spaceraiders/world/Planet.kt
@@ -35,9 +35,8 @@ class Planet(val id: Int, val location: SpaceLocation, val expireTime: Long, val
var world: World? = null
- fun isLoaded(): Boolean{
- return world != null
- }
+ val isLoaded: Boolean
+ get() = world != null
fun loadWorld(){
val wc = WorldCreator("planet$id")
@@ -68,7 +67,6 @@ class Planet(val id: Int, val location: SpaceLocation, val expireTime: Long, val
} finally {
c.close()
}
- throw SQLException("There was an error inserting a new planet into the database.")
}
fun createTable(): String {
diff --git a/src/test/java/Test.kt b/src/test/java/Test.kt
deleted file mode 100644
index 8cb9ac1..0000000
--- a/src/test/java/Test.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2018 Nicholas Harris
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
- * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * Created by owner on 1/8/2018.
- */
-class Test {
-
- fun main(vararg params: String){
-
- }
-
-}
\ No newline at end of file