Item-Attribute Framework for Minecraft Server

Overview

ArathothIII

开源免费的Minecraft物品属性插件开发框架

TODO

  • 基础属性包

API

快速创建一个属性

使用Kotlin优雅的DSL语法快速创建一个属性

@Register
val damage = createAttribute("arathoth", "damage") {
    event(EntityDamageByEntityEvent::class.java) {
        val status = damager.status(this@createAttribute) ?: return@event
        damage += status.generateValue()
    }
    config {
        set("patterns", listOf("[VALUE] damage"))
    }
}

自定义你的属性值类型

Arathoth支持储存任意类型的属性值,而不仅仅是数值

如果你希望储存给你的某个属性储存自定义类型的属性值,你需要创建一个自定义值类型

, val percent: Double ) : AttributeData { override fun append(data: AttributeData): AttributeData { data as NumberAttributeData return NumberAttributeData( range.mapIndexed { index, d -> d + data.range[index] }, percent + data.percent ) } fun generateValue(): Double { return random(range[0], range[1]) * (1 + percent / 100) } }">
// 这是一个属性没有指定值类型时的默认值类型 - 数值类型 供参考
val NUMBER = object : AttributeValueType<NumberAttributeData> {

    override fun parse(section: ConfigurationSection): NumberAttributeData {
        val content = section.getString("value")!!
        // 百分比不支持范围
        if (content.endsWith("%")) {
            return NumberAttributeData(
                listOf(0.0, 0.0),
                NumberConversions.toDouble(content.removeSuffix("%"))
            )
        }
        if (content.contains("~")) {
            val array = content.split("~")
                .map { NumberConversions.toDouble(it) }
                .sorted()
            return NumberAttributeData(array, 0.0)
        }
        val value = NumberConversions.toDouble(content)
        return NumberAttributeData(
            listOf(value, value),
            0.0
        )
    }
}

// 数值属性Data
data class NumberAttributeData(
    val range: List<Double>,
    val percent: Double
) : AttributeData {
    override fun append(data: AttributeData): AttributeData {
        data as NumberAttributeData
        return NumberAttributeData(
            range.mapIndexed { index, d -> d + data.range[index] },
            percent + data.percent
        )
    }

    fun generateValue(): Double {
        return random(range[0], range[1]) * (1 + percent / 100)
    }
}

自定义属性读取方式

Arathoth的主体属性值是储存在位于配置文件的属性集中的,这也是Arathoth于同类属性插件的优势之一,任何物品的属性都在服务器管理员的掌控之中。

但Arathoth仍然为开发者提供了定义属性读取方式的接口,并默认提供了从Lore/NBT中读取属性值的实现

[-+]?\\d+(?:\\.\\d+)?)(?:-?)((? [-+]?\\d+(?:\\.\\d+)?)?)" private val percentRegex = "(? [-+]?\\d+(?:\\.\\d+)?)%" override fun parse(key: AttributeKey , item: ItemStack): NumberAttributeData { if (!Arathoth.enableLore) return NumberAttributeData(listOf(0.0, 0.0), 0.0) val conf = key.config if (!regexMap.containsKey(key.node) || !percentRegexMap.containsKey(key.node)) { val regex = conf.getStringList("lore").map { it.replace("[VALUE]", regex).toRegex() } val percentRegex = conf.getStringList("lore").map { it.replace("[VALUE]", percentRegex).toRegex() } regexMap[key.node] = regex percentRegexMap[key.node] = percentRegex } val regex = regexMap[key.node]!! val percentRegex = percentRegexMap[key.node]!! val lore = item.lore var min = 0.0 var max = 0.0 var percent = 0.0 for (s in lore) { regex.forEach { it.findAll(s).forEach { r -> val groups = r.groups as MatchNamedGroupCollection val min1 = groups["min"]?.value?.toDouble() ?: 0.0 val max1 = groups["max"]?.value?.toDouble() ?: min1 min += min1 max += max1 } } percentRegex.forEach { it.findAll(s).forEach { r -> val groups = r.groups as MatchNamedGroupCollection val pct = groups["percent"]?.value?.toDouble() ?: 0.0 percent += pct } } } return NumberAttributeData(listOf(min, max).sorted(), percent) } } // NBT属性解析器 val PARSER_NBT = object : ExtraAttributeParser { override fun parse(key: AttributeKey , item: ItemStack): NumberAttributeData { val itemTag = item.getItemTag().getDeep("Arathoth.NBTExtra.$key")?.asCompound() if (itemTag != null) { val min = itemTag["min"]?.asDouble() ?: 0.0 val max = itemTag["max"]?.asDouble() ?: min val percent = itemTag["percent"]?.asDouble() ?: 0.0 return NumberAttributeData(listOf(min, max).sorted(), percent) } return NumberAttributeData(listOf(0.0, 0.0), 0.0) } }">
// Lore属性解析器
val PARSER_LORE = object : ExtraAttributeParser<NumberAttributeData> {

    private val regexMap = mutableMapOf<String, List<Regex>>()
    private val percentRegexMap = mutableMapOf<String, List<Regex>>()
    private val regex = "(?
        
         [-+]?
         \\d+(?:
         \\.
         \\d+)?)(?:-?)((?
         
          [-+]?
          \\d+(?:
          \\.
          \\d+)?)?)
          "
         
        
    private val percentRegex = "(?
        
         [-+]?
         \\d+(?:
         \\.
         \\d+)?)%
         "
        

    override fun parse(key: AttributeKey<NumberAttributeData>, item: ItemStack): NumberAttributeData {
        if (!Arathoth.enableLore) return NumberAttributeData(listOf(0.0, 0.0), 0.0)
        val conf = key.config
        if (!regexMap.containsKey(key.node) || !percentRegexMap.containsKey(key.node)) {
            val regex = conf.getStringList("lore").map { it.replace("[VALUE]", regex).toRegex() }
            val percentRegex = conf.getStringList("lore").map { it.replace("[VALUE]", percentRegex).toRegex() }
            regexMap[key.node] = regex
            percentRegexMap[key.node] = percentRegex
        }
        val regex = regexMap[key.node]!!
        val percentRegex = percentRegexMap[key.node]!!
        val lore = item.lore
        var min = 0.0
        var max = 0.0
        var percent = 0.0
        for (s in lore) {
            regex.forEach {
                it.findAll(s).forEach { r ->
                    val groups = r.groups as MatchNamedGroupCollection
                    val min1 = groups["min"]?.value?.toDouble() ?: 0.0
                    val max1 = groups["max"]?.value?.toDouble() ?: min1
                    min += min1
                    max += max1
                }
            }
            percentRegex.forEach {
                it.findAll(s).forEach { r ->
                    val groups = r.groups as MatchNamedGroupCollection
                    val pct = groups["percent"]?.value?.toDouble() ?: 0.0
                    percent += pct
                }
            }
        }
        return NumberAttributeData(listOf(min, max).sorted(), percent)
    }
}

// NBT属性解析器
val PARSER_NBT = object : ExtraAttributeParser<NumberAttributeData> {
    override fun parse(key: AttributeKey<NumberAttributeData>, item: ItemStack): NumberAttributeData {
        val itemTag = item.getItemTag().getDeep("Arathoth.NBTExtra.$key")?.asCompound()
        if (itemTag != null) {
            val min = itemTag["min"]?.asDouble() ?: 0.0
            val max = itemTag["max"]?.asDouble() ?: min
            val percent = itemTag["percent"]?.asDouble() ?: 0.0
            return NumberAttributeData(listOf(min, max).sorted(), percent)
        }
        return NumberAttributeData(listOf(0.0, 0.0), 0.0)
    }
}

自定义约束条件

每一个属性集都可以设置对应的约束集,一旦没有通过约束集,该属性集中的属性将不会被加载

Arathoth已经默认实现了以下使用到的所有约束集

exampleItem:
# 游戏中手持物品/arathoth addattrtag 
   <文件名>
    .
    <节点路径>
      (example.exampleItem)
    
   
# 条件列表,不满足其中任何一条则该属性节点无法生效
# 可用约束条件
# bind - 绑定是否视为加载该属性的条件之一,若视为,非该物品绑定的玩家将不会读取该物品的属性
# type - 该物品第一行是否含有这段字符串(去掉颜色之后)
# slot - 物品在玩家背包中的哪个槽位时物品属性生效(槽位id/main)
# perm - 权限节点约束
# level - 等级约束,可用符号 > < >= <= =
# kether - kether脚本条件,自由度极高,任你发挥 (返回值必须为boolean类型)
  rules:
  - type(主武器)
  - bind
  - slot(36, main, off)
  - perm(arathoth.exampleItem)
  - level(>=233)
  - kether(check player food level >= 10)
  # value 写法由对应属性的开发者决定
  # 在名称重复的情况下 在前面加上(namespace)来特指某属性
  attributes:
    (arathoth)damage:
      value: 10

当然,作为一款自定义度极高的属性插件,约束条件自然也是允许开发者自定义的。我们来看看level这个约束条件的实现。

=") -> player.level >= NumberConversions.toInt(content.substring(2)) content.startsWith("<=") -> player.level <= NumberConversions.toInt(content.substring(2)) content.startsWith(">") -> player.level > NumberConversions.toInt(content.substring(1)) content.startsWith("<") -> player.level < NumberConversions.toInt(content.substring(1)) content.startsWith("=") -> player.level == NumberConversions.toInt(content.substring(1)) else -> true } } }">
@RuleImpl(key = "level")
object RuleLevel : Rule {
    override fun judge(player: Player, slot: Int, item: ItemStack, content: String): Boolean {
        return when {
            content.startsWith(">=") -> player.level >= NumberConversions.toInt(content.substring(2))
            content.startsWith("<=") -> player.level <= NumberConversions.toInt(content.substring(2))
            content.startsWith(">") -> player.level > NumberConversions.toInt(content.substring(1))
            content.startsWith("<") -> player.level < NumberConversions.toInt(content.substring(1))
            content.startsWith("=") -> player.level == NumberConversions.toInt(content.substring(1))
            else -> true
        }
    }
}
You might also like...
A cross-platform Java game Engine (Framework) , support JavaFX / Android / IOS / HTML5 / Linux / MAC / Windows
A cross-platform Java game Engine (Framework) , support JavaFX / Android / IOS / HTML5 / Linux / MAC / Windows

Loon Game Engine (Java Game Framework) EN / KR Free Game Resources Links Download Loon Game Engine Only Android-studio Template : androidstudio-templa

A small project demonstrates how to manipulate to TenIO framework.
A small project demonstrates how to manipulate to TenIO framework.

TenIO Common Module TenIO is an open-source project to create multiplayer online games that includes a java NIO (Non-blocking I/O) based server specif

Extensive game framework written in Kotlin

CGS is a minigame framework I wrote in December of 2021. This project was closed-source, but unfortunately, a series of events led me to decide to open-source it.

Desktop/Android/HTML5/iOS Java game development framework
Desktop/Android/HTML5/iOS Java game development framework

Cross-platform Game Development Framework libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux

This is a project designed to help controlling Android MediaPlayer class. It makes it easier to use MediaPlayer ListView and RecyclerView. Also it tracks the most visible item in scrolling list. When new item in the list become the most visible, this library gives an API to track it. 类似 iOS 带弹簧效果的左右滑动控件,可作为 AbsListView 和 RecyclerView 的 item(作为 AbsListView 的 item 时的点击事件参考代码家的 https://github.com/daimajia/AndroidSwipeLayout )
类似 iOS 带弹簧效果的左右滑动控件,可作为 AbsListView 和 RecyclerView 的 item(作为 AbsListView 的 item 时的点击事件参考代码家的 https://github.com/daimajia/AndroidSwipeLayout )

🏃 BGASwipeItemLayout-Android 🏃 类似iOS带弹簧效果的左右滑动控件,可作为AbsListView和RecyclerView的item。支持给BGASwipeItemLayout和其子控件设置margin和padding属性 效果图 Gradle依赖 dependen

ItemDecorator - Custom item decorator for adding divider for only the first item of a RecyclerView

ItemDecorator Custom item decorator for adding divider for only the first item o

Android Navigation Fragment Share Element Example: Use Share Element Transition with recyclerView Item and ViewPager2 Item.
Android Navigation Fragment Share Element Example: Use Share Element Transition with recyclerView Item and ViewPager2 Item.

Android-Navigation-Fragment-Share-Element-Example 说明 Android 使用Navigation导航切换Fragment中使用共享元素过渡动画的例子:将在listFragment的RecyclerView的Item共享元素过渡到pagerFragme

This library is used to control an attribute if it comes to null

This library is used to control an attribute if it comes to null, what it will do is remove that null and give it a default value. Ideal for dealing with business models where attributes can be nullable.

This tool patches the CVE-2021-44228 Log4J vulnerability present in all minecraft versions NOTE THIS TOOL MUST BE RE-RUN after downloading or updating versions of minecraft as its not a perminent patch

WARNING THIS EXPLOIT EFFECTS BOTH CLIENTS AND SERVERS There is currently a exploit going around that affects all versions of Minecraft this exploit ab

FDPClient-EDITED - A free mixin-based injection hacked-client for Minecraft using Minecraft Forge based on LiquidBounce

FDPClient A free mixin-based injection hacked-client for Minecraft using Minecra

A minecraft modification based on Fabric with Yarn Mappings, developed for the newest version of the sandbox game Minecraft.

JupiterClient A minecraft modification based on Fabric with Yarn Mappings, developed for the newest version of the sandbox game Minecraft. Building th

Gradle plugin adding a task to run a Paper Minecraft server

Run Paper Run Paper is a Gradle plugin which adds a task to automatically download and run a Paper Minecraft server along with your plugin built by Gr

VirtualTag is a name tag edit plugin for minecraft server

VirtualTag VirtualTag is a NameTag Edit plugin for modern minecraft server Support Version 1.17.x Download https://github.com/jiangdashao/VirtualTag/r

Minecraft JE Server Programming with JS like Skript, Trigger Reactor

mine.js(Developing) Minecraft Java Edition Scripting with JS(V8 Engine) by Netherald How to apply? Download Paper or Bungee Version. and put it to plu

A powerful Minecraft Server Software coming from the future

Mirai A powerful Minecraft Server Software coming from the future Mirai is ❗ under heavy development ❗ and contributions are welcome! Features 30% fas

Minecraft Server Software specially designed for Thicc SMP. Here on GitHub without the private patches, just a normal hybrid JettPack-Pufferfish-Empirecraft fork

AlynaaMC A private, custom server software for Thicc SMP and a fork of Pufferfish. Here on GitHub with patches from JettPack, Airplane and Pufferfish

This command line program can extract chat messages send on the Minecraft server HGLabor

HGLabor-Log-Extractor Das Programm durchläuft einmalig deine Minecraft-Logs und sammelt alle Nachrichten heraus, die auf HGLabor geschrieben wurden. K

🚧 A fully open-source project for creating and maintaining a Kotlin-based Minecraft: Java Edition server.

Hexalite: Java Edition ⚠️ WARNING: The Hexalite Network is a work in progress. It is not yet ready for production. You may encounter bugs and other is

Owner
Rain
Student | Software Engineering | Learning Android & Web-FrontEnd | Focusing on learning
Rain
OpenModInstaller is an innovative open-source application for universal Minecraft mod management.

OpenModInstaller is an innovative open-source application for universal Minecraft mod management.

OpenModInstaller 11 Dec 9, 2021
Application for downloading and installing mods for minecraft

Mods Rainbow Application for downloading and installing mods for minecraft. Also user can choose favourites mods. Table of Contents Screenshots Genera

Vladyslav 3 May 8, 2022
Minosoft is an open source minecraft client, written from scratch in kotlin (and java).

Minosoft Minosoft is an open source minecraft client, written from scratch in kotlin (and java). It aims to bring more functionality and stability. No

null 151 Dec 31, 2022
Radio - a Minecraft Servers plugin for providing the best experience of interaction with broadcasting

Radio Radio is a Minecraft Servers plugin for providing the best experience of interaction with broadcasting. Installation Download required version f

Viktor 3 Dec 14, 2022
The Xlite Game Server.

Xlite 2.0 Xlite is a modular kotlin based RSPS. The goal of Xlite 2.0 is to provide the community with a stable and powerful sandbox to experiment wit

null 11 Nov 19, 2021
The Xlite Game Server.

Xlite 2.0 Xlite is a modular kotlin based RSPS. The goal of Xlite 2.0 is to provide the community with a stable and powerful sandbox to experiment wit

Runetopic 11 Nov 19, 2021
A Ktor-based server that handles game process, user registration and packs provision

Polyhoot! Server backend A Ktor-based server that handles game process, user registration and packs provision Deploying server locally You can deploy

Polyhoot! 2 May 31, 2022
WynnLib is a Fabric mod that aims to provide data-related functionalities for the server Wynncraft

WynnLib is a Fabric mod that aims to provide data-related functionalities for the server Wynncraft. The mod inherits from the mod WynnInvManager (WIM), but comes up with a better framework design and supports newer Minecraft versions. As an open-source project, the contribution is welcome.

Sihan 13 Nov 20, 2022
An easy open source Android Native Game FrameWork.

JustWeEngine - Android Game FrameWork An easy open source Android Native Game FrameWork. Engine Flow Chart How To Use? Import Engine's module as Libra

JustWe 767 Dec 8, 2022
Desktop/Android/HTML5/iOS Java game development framework

Cross-platform Game Development Framework libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux

libgdx 20.9k Jan 8, 2023