Compare commits
5 Commits
03ddc4eee1
...
146a7a602f
| Author | SHA1 | Date | |
|---|---|---|---|
| 146a7a602f | |||
| 1057f6ccaf | |||
| f5e58775ab | |||
| a4febfacb9 | |||
| 57baae0a05 |
@@ -0,0 +1,35 @@
|
||||
name: Build Plugin
|
||||
run-name: Building Plugin 🚀
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'ver/**'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build with Maven
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Set up JDK 25 and enable Maven cache
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'liberica'
|
||||
java-version: '25'
|
||||
cache: 'maven'
|
||||
|
||||
- name: Set up Maven
|
||||
uses: stCarolas/setup-maven@v5
|
||||
with:
|
||||
maven-version: 3.9.16
|
||||
|
||||
- name: Build and package with Maven
|
||||
run: mvn -B package
|
||||
|
||||
- name: Upload built artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: maven-artifacts
|
||||
path: target/spigot/*.jar
|
||||
@@ -6,17 +6,85 @@
|
||||
|
||||
<groupId>xyz.fortern</groupId>
|
||||
<artifactId>fortern-helper</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>fortern-helper</name>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.helpch.at/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
<kotlin.version>2.4.0</kotlin.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>26.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Kotlin Stdlib https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- JetBrains Java Annotations https://mvnrepository.com/artifact/org.jetbrains/annotations -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>26.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Adventure API https://mvnrepository.com/artifact/net.kyori/adventure-api -->
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.26.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Adventure Platform Bukkit https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit -->
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- PlaceholderAPI -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.12.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- NBT-API -->
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api-plugin</artifactId>
|
||||
<version>2.15.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
@@ -50,6 +118,11 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-spigot-${project.version}</finalName>
|
||||
<outputDirectory>${project.build.directory}/spigot</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
@@ -59,48 +132,4 @@
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>26.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Kotlin Stdlib https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
<!-- JetBrains Java Annotations https://mvnrepository.com/artifact/org.jetbrains/annotations -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>26.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Adventure API https://mvnrepository.com/artifact/net.kyori/adventure-api -->
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.26.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Adventure Platform Bukkit https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit -->
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.4.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,23 +1,39 @@
|
||||
package xyz.fortern.forternhelper
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.fortern.forternhelper.command.HelperCommand
|
||||
import xyz.fortern.forternhelper.listener.ForternListener
|
||||
import xyz.fortern.forternhelper.placeholder.ForternExpansion
|
||||
|
||||
class Helper : JavaPlugin() {
|
||||
private lateinit var adventure: BukkitAudiences
|
||||
|
||||
private lateinit var expansion: PlaceholderExpansion
|
||||
|
||||
override fun onEnable() {
|
||||
// Plugin startup logic
|
||||
this.adventure = BukkitAudiences.create(this)
|
||||
logger.info("Registering listeners...")
|
||||
// register listeners
|
||||
Bukkit.getPluginManager().registerEvents(ForternListener(this), this)
|
||||
logger.info("Registering commands...")
|
||||
// register commands
|
||||
Bukkit.getPluginCommand("helper")?.setExecutor(HelperCommand(this, adventure))
|
||||
// register placeholders
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
expansion = ForternExpansion(this)
|
||||
logger.info("Registering placeholders...")
|
||||
expansion.register()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
// Plugin shutdown logic
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
expansion.unregister()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package xyz.fortern.forternhelper.command
|
||||
|
||||
import de.tr7zw.nbtapi.NBT
|
||||
import de.tr7zw.nbtapi.iface.ReadWriteNBT
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.format.NamedTextColor
|
||||
@@ -9,6 +11,8 @@ import org.bukkit.command.CommandSender
|
||||
import org.bukkit.command.TabExecutor
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
class HelperCommand(
|
||||
private val plugin: JavaPlugin,
|
||||
@@ -54,8 +58,24 @@ class HelperCommand(
|
||||
}
|
||||
}
|
||||
return when (args[0]) {
|
||||
"help" -> onHelp(sender, exe)
|
||||
"loadlevel" -> onLoadLevel(sender, args, exe)
|
||||
"help" -> {
|
||||
onHelp(sender, exe)
|
||||
}
|
||||
|
||||
"loadlevel" -> {
|
||||
onLoadLevel(sender, args, exe)
|
||||
}
|
||||
|
||||
"setblock" -> {
|
||||
setBlockFromNbt(sender, args, exe)
|
||||
null
|
||||
}
|
||||
|
||||
"getitem" -> {
|
||||
getItemFromNbt(sender, args, exe)
|
||||
null
|
||||
}
|
||||
|
||||
else -> {
|
||||
if (exe) {
|
||||
adventure.sender(sender).sendMessage(Component.text("错误的子命令"))
|
||||
@@ -68,6 +88,54 @@ class HelperCommand(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getItemFromNbt(sender: CommandSender, args: List<String>, exe: Boolean) {
|
||||
// args[0]:getitem | args[1]:0 | args[2]:txt
|
||||
if (!exe) return
|
||||
if (sender !is Player) return
|
||||
if (!sender.isOp) return
|
||||
if (args.size < 2) return
|
||||
val i = args[1]
|
||||
val isNbt = if (args.size > 2) args[2] == "nbt" else false
|
||||
val itemNbtDir = File(plugin.dataFolder, "item-nbt")
|
||||
val nbt = if (isNbt) {
|
||||
val file = File(itemNbtDir, "${i}.nbt")
|
||||
if (!file.exists()) return
|
||||
NBT.readFile(file)
|
||||
} else {
|
||||
val file = File(itemNbtDir, "${i}.txt")
|
||||
if (!file.exists()) return
|
||||
NBT.parseNBT(FileReader(file).readAllAsString())
|
||||
}
|
||||
sender.inventory.addItem(NBT.itemStackFromNBT(nbt))
|
||||
return
|
||||
}
|
||||
|
||||
private fun setBlockFromNbt(sender: CommandSender, args: List<String>, exe: Boolean) {
|
||||
// args[0]:setblock | args[1]:0 | args[2]:txt
|
||||
if (!exe) return
|
||||
if (sender !is Player) return
|
||||
if (!sender.isOp) return
|
||||
if (args.size < 2) return
|
||||
val i = args[1]
|
||||
val isNbt = if (args.size > 2) args[2] == "nbt" else false
|
||||
val world = sender.world
|
||||
val blockState = world.getBlockState(0, 128, 0)
|
||||
val itemNbtDir = File(plugin.dataFolder, "block-nbt")
|
||||
val readWriteNBT = if (isNbt) {
|
||||
val file = File(itemNbtDir, "${i}.nbt")
|
||||
if (!file.exists()) return
|
||||
NBT.readFile(file)
|
||||
} else {
|
||||
val file = File(itemNbtDir, "${i}.txt")
|
||||
if (!file.exists()) return
|
||||
NBT.parseNBT(FileReader(file).readAllAsString())
|
||||
}
|
||||
NBT.modify(blockState) { nbt: ReadWriteNBT ->
|
||||
nbt.mergeCompound(readWriteNBT)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
private fun onHelp(sender: CommandSender, exe: Boolean): List<String>? {
|
||||
if (exe) sendHelp(sender)
|
||||
return null
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package xyz.fortern.forternhelper.placeholder
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
|
||||
|
||||
class ForternExpansion(
|
||||
val plugin: JavaPlugin
|
||||
) : PlaceholderExpansion() {
|
||||
override fun getIdentifier(): String {
|
||||
return "fortern"
|
||||
}
|
||||
|
||||
override fun getAuthor(): String {
|
||||
return plugin.description.authors.toString()
|
||||
}
|
||||
|
||||
override fun getVersion(): String {
|
||||
return plugin.description.version
|
||||
}
|
||||
|
||||
override fun persist(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onRequest(player: OfflinePlayer, params: String): String {
|
||||
return if (params.startsWith("loadlevel_")) {
|
||||
// e.g. peace_the_nether_x,z
|
||||
val first = params.indexOf('_')
|
||||
if (first < 0) return "unknown"
|
||||
val last = params.lastIndexOf('_')
|
||||
if (last <= first) return "unknown"
|
||||
val chunkPos = params.substring(last + 1)
|
||||
val split = chunkPos.split(',')
|
||||
if (split.size < 2) return "unknown"
|
||||
val chunkX = split[0]
|
||||
val chunkZ = split[1]
|
||||
val worldName = params.substring(first + 1, last)
|
||||
val world = Bukkit.getWorld(worldName) ?: return "unknown"
|
||||
try {
|
||||
val x = Integer.parseInt(chunkX)
|
||||
val z = Integer.parseInt(chunkZ)
|
||||
world.getChunkAt(x, z).loadLevel.toString()
|
||||
} catch (_: NumberFormatException) {
|
||||
"unknown"
|
||||
}
|
||||
} else {
|
||||
"unknown"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,10 @@ version: '${version}'
|
||||
authors: [ Fortern ]
|
||||
api-version: '26.1'
|
||||
main: xyz.fortern.forternhelper.Helper
|
||||
softdepend:
|
||||
- PlaceholderAPI
|
||||
depend:
|
||||
- NBTAPI
|
||||
|
||||
libraries:
|
||||
- org.jetbrains.kotlin:kotlin-stdlib:2.3.21
|
||||
|
||||
Reference in New Issue
Block a user