All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.monun.kommand.KommandArgument.kt Maven / Gradle / Ivy

There is a newer version: 3.1.7
Show newest version
/*
 * Kommand
 * Copyright (C) 2021 Monun
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package io.github.monun.kommand

import com.destroystokyo.paper.profile.PlayerProfile
import com.google.gson.JsonObject
import io.github.monun.kommand.loader.LibraryLoader
import io.github.monun.kommand.wrapper.*
import io.github.monun.kommand.wrapper.Rotation
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentLike
import org.bukkit.*
import org.bukkit.advancement.Advancement
import org.bukkit.block.Block
import org.bukkit.block.data.BlockData
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.Recipe
import org.bukkit.potion.PotionEffectType
import org.bukkit.scoreboard.DisplaySlot
import org.bukkit.scoreboard.Objective
import org.bukkit.scoreboard.Team
import java.util.*

// 인수
@KommandDSL
interface KommandArgument {
    companion object : KommandArgumentSupport by KommandArgumentSupport.INSTANCE

    fun suggests(provider: KommandSuggestion.(context: KommandContext) -> Unit)
}

interface KommandArgumentSupport {
    companion object {
        val INSTANCE = LibraryLoader.loadNMS(KommandArgumentSupport::class.java)
    }

    // com.mojang.brigadier.arguments

    fun bool(): KommandArgument

    fun int(minimum: Int = Int.MIN_VALUE, maximum: Int = Int.MAX_VALUE): KommandArgument

    fun float(minimum: Float = -Float.MAX_VALUE, maximum: Float = Float.MAX_VALUE): KommandArgument

    fun double(minimum: Double = -Double.MAX_VALUE, maximum: Double = Double.MAX_VALUE): KommandArgument

    fun long(minimum: Long = Long.MIN_VALUE, maximum: Long = Long.MAX_VALUE): KommandArgument

    fun string(type: StringType = StringType.SINGLE_WORD): KommandArgument

    // net.minecraft.commands.arguments

    fun angle(): KommandArgument

    fun color(): KommandArgument

    fun component(): KommandArgument

    fun compoundTag(): KommandArgument

    fun dimension(): KommandArgument

    fun entityAnchor(): KommandArgument

    fun entity(): KommandArgument

    fun entities(): KommandArgument>

    fun player(): KommandArgument

    fun players(): KommandArgument>

    fun summonableEntity(): KommandArgument

    fun profile(): KommandArgument>

    fun enchantment(): KommandArgument

    fun message(): KommandArgument

    fun mobEffect(): KommandArgument

    //    fun nbtPath(): KommandArgument<*> [NbtTagArgument]

    fun objective(): KommandArgument

    fun objectiveCriteria(): KommandArgument

    //    fun operation(): KommandArgument<*> [OperationArgument]

    fun particle(): KommandArgument

    fun intRange(): KommandArgument

    fun doubleRange(): KommandArgument>

    fun advancement(): KommandArgument

    fun recipe(): KommandArgument

    //    ResourceLocationArgument#getPredicate()

    //    ResourceLocationArgument#getItemModifier()

    fun displaySlot(): KommandArgument

    fun score(): KommandArgument

    fun scores(): KommandArgument>

    fun slot(): KommandArgument

    fun team(): KommandArgument

    fun time(): KommandArgument

    fun uuid(): KommandArgument

    // net.minecraft.commands.arguments.blocks

    fun blockPredicate(): KommandArgument<(Block) -> Boolean>

    fun blockState(): KommandArgument

    // net.minecraft.commands.arguments.coordinates

    fun blockPosition(type: PositionLoadType = PositionLoadType.LOADED): KommandArgument

    fun blockPosition2D(): KommandArgument

    fun position(): KommandArgument

    fun position2D(): KommandArgument

    fun rotation(): KommandArgument

    fun swizzle(): KommandArgument>

    // net.minecraft.commands.arguments.item

    fun function(): KommandArgument<() -> Unit>

    fun item(): KommandArgument

    fun itemPredicate(): KommandArgument<(ItemStack) -> Boolean>

    // dynamic

    fun  dynamic(
        type: StringType = StringType.SINGLE_WORD,
        function: KommandSource.(context: KommandContext, input: String) -> T?
    ): KommandArgument

    fun  dynamicByMap(
        map: Map,
        type: StringType = StringType.SINGLE_WORD,
        tooltip: ((T) -> ComponentLike)? = null
    ): KommandArgument {
        return dynamic(type) { _, input ->
            map[input]
        }.apply {
            suggests {
                if (tooltip == null) {
                    suggest(map.keys)
                } else {
                    suggest(map, tooltip)
                }
            }
        }
    }

    fun > dynamicByEnum(
        set: EnumSet,
        tooltip: ((T) -> ComponentLike)? = null
    ): KommandArgument {
        return dynamic(StringType.SINGLE_WORD) { _, input ->
            set.find { it.name == input }
        }.apply {
            suggests {
                suggest(set, { it.name }, tooltip)
            }
        }
    }
}

enum class StringType {
    SINGLE_WORD,
    QUOTABLE_PHRASE,
    GREEDY_PHRASE
}

enum class PositionLoadType {
    LOADED,
    SPAWNABLE
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy