Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from deveworld/feature/rebar
Browse files Browse the repository at this point in the history
2.0.0 Release
  • Loading branch information
deveworld committed Oct 9, 2023
2 parents 95dbca2 + a23b1e9 commit 9f55cf9
Show file tree
Hide file tree
Showing 17 changed files with 871 additions and 194 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "dev.worldsw"
version = "1.1.0"
version = "2.0.0"
description = "The plugin for the architecture king(YouTuber)."

repositories {
Expand All @@ -20,7 +20,7 @@ java {
}

dependencies {
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")

implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
Expand Down Expand Up @@ -50,7 +50,7 @@ tasks {
}

runServer {
minecraftVersion("1.20.1")
minecraftVersion("1.20.2")
jvmArgs("-Dcom.mojang.eula.agree=true")
}

Expand Down
49 changes: 31 additions & 18 deletions src/main/kotlin/dev/worldsw/archKing/ArchKingPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,61 +1,74 @@
package dev.worldsw.archKing

import dev.worldsw.archKing.block.AKBlock
import dev.worldsw.archKing.block.AKOverlapBlock
import dev.worldsw.archKing.command.AKCommand
import dev.worldsw.archKing.event.AKBlockEvent
import dev.worldsw.archKing.recipe.AKRecipe
import dev.worldsw.archKing.data.AKStorage
import dev.worldsw.archKing.event.AKGypsumEvent
import dev.worldsw.archKing.event.AKRebarEvent
import dev.worldsw.archKing.event.AKStorageEvent
import dev.worldsw.archKing.event.*
import dev.worldsw.archKing.item.AKItem
import dev.worldsw.archKing.rebar.AKRebar
import org.bukkit.Bukkit
import org.bukkit.command.TabCompleter
import org.bukkit.event.Listener
import org.bukkit.plugin.java.JavaPlugin

class ArchKingPlugin: JavaPlugin(), Listener {
lateinit var storage: AKStorage
lateinit var akRebar: AKRebar
lateinit var akItem: AKItem
lateinit var akBlock: AKBlock
lateinit var akOverlapBlock: AKOverlapBlock

override fun onEnable() {
akRebar = AKRebar(this)
storage = AKStorage(this)

storage.init()
akItem = AKItem(this)
akBlock = AKBlock(this)
akOverlapBlock = AKOverlapBlock(this)
AKRecipe(this)

server.pluginManager.registerEvents(this, this)
server.pluginManager.registerEvents(AKStorageEvent(this), this)
server.pluginManager.registerEvents(AKRebarEvent(this), this)
server.pluginManager.registerEvents(AKOverlapBlockEvent(this), this)
server.pluginManager.registerEvents(AKGypsumEvent(this), this)
server.pluginManager.registerEvents(AKBlockEvent(this), this)
server.pluginManager.registerEvents(AKFallEvent(this), this)
server.pluginManager.registerEvents(AKPaintEvent(this), this)

val voidTabCompleter = TabCompleter { _, _, _, _ -> mutableListOf() }
val commandList = listOf("archkingitem")
val getAkiCommands = listOf("archkingitem")
val commandList = listOf("akitem", "akgravity")
commandList.forEach {
getCommand(it)!!.setExecutor(AKCommand(this))
if (it in getAkiCommands) {
getCommand(it)!!.tabCompleter = TabCompleter { _, _, label, args ->
if (label.equals(it, true) && args.size == 1) {
akItem.getAllProperties()
} else {
mutableListOf()
when (it) {
"akitem" -> {
getCommand(it)!!.tabCompleter = TabCompleter { _, _, label, args ->
if (label.equals(it, true) && args.size == 1) {
akItem.getAllProperties()
} else {
mutableListOf()
}
}
}
} else {
getCommand(it)!!.tabCompleter = voidTabCompleter

"akgravity" -> {
getCommand(it)!!.tabCompleter = TabCompleter { _, _, label, args ->
if (label.equals(it, true) && args.size == 1) {
mutableListOf("concrete", "wood")
} else {
mutableListOf()
}
}
}

else -> {
getCommand(it)!!.tabCompleter = voidTabCompleter
}
}
}
}

override fun onDisable() {
storage.saveData()
Bukkit.getScheduler().cancelTasks(this)
}
}
76 changes: 72 additions & 4 deletions src/main/kotlin/dev/worldsw/archKing/block/AKBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import dev.worldsw.archKing.data.AKStorage
import dev.worldsw.archKing.item.AKItem
import dev.worldsw.archKing.item.AKItemType
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.block.Block
import org.bukkit.block.BlockFace
import org.bukkit.entity.Entity
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataType


class AKBlock(private val plugin: ArchKingPlugin) {
fun isAKBlock(block: Block): Boolean {
return getCustomBlockData(block) != null
Expand Down Expand Up @@ -57,6 +62,7 @@ class AKBlock(private val plugin: ArchKingPlugin) {
AKItem.NOT_CUSTOM_ITEM
)
if (dataAKItemType == AKItem.NOT_CUSTOM_ITEM) return
if (dataAKItemType in AKOverlapBlock.OVERLAP_BLOCKS) return
plugin.akBlock.addCustomBlockData(block, dataAKItemType)
if (dataAKItemType == AKItemType.READY_MIXED_CONCRETE) rmcToc(block)
}
Expand All @@ -71,24 +77,86 @@ class AKBlock(private val plugin: ArchKingPlugin) {
plugin.akBlock.addCustomBlockData(newBlock, dataAKItemType)
}

fun fallAKBlock(block: Block, entity: Entity) {
if (entity.type != EntityType.FALLING_BLOCK) return
val dataAKItemType = plugin.akBlock.getCustomBlockData(block)
if (dataAKItemType == null) {
plugin.akBlock.placeAKItem(entity.persistentDataContainer, block)
} else {
plugin.akBlock.removeCustomBlockData(block)
entity.persistentDataContainer.set(
NamespacedKey(plugin, AKItem.CUSTOM_ITEM),
PersistentDataType.INTEGER,
dataAKItemType
)
}
}

private fun breakRMC(block: Block) {
val data = plugin.storage.getMemory(AKStorage.READY_MIXED_CONCRETE_HARD, block.location.toString()) ?: return
plugin.storage.removeMemory(AKStorage.READY_MIXED_CONCRETE_HARD, block.location.toString())
plugin.server.scheduler.cancelTask(data.asJsonObject.get("schedule").asInt)
}

fun renderGravity(player: Player) {
val wood = plugin.storage.getData(AKStorage.GRAVITY, AKStorage.WOOD_GRAVITY)!!.asBoolean
val concrete = plugin.storage.getData(AKStorage.GRAVITY, AKStorage.CONCRETE_GRAVITY)!!.asBoolean

if (!(wood || concrete)) return

val radius = 50

if (wood) {
for (block in getNearbyBlocks(player.location, radius)) {
val location = block.location
if (block.type in listOf(Material.OAK_PLANKS, Material.ACACIA_PLANKS, Material.BAMBOO_PLANKS)) {
location.getWorld().spawnFallingBlock(
location.toCenterLocation().add(0.0, -0.5, 0.0),
block.type.createBlockData()
)
block.type = Material.AIR
}
}
}
if (concrete) {
for (block in getNearbyBlocks(player.location, radius)) {
val location = block.location
if (plugin.akBlock.getCustomBlockData(block) == AKItemType.CONCRETE) {
val entity = location.getWorld().spawnFallingBlock(
location.toCenterLocation().add(0.0, -0.5, 0.0),
block.type.createBlockData()
)
plugin.akBlock.fallAKBlock(block, entity)
block.type = Material.AIR
}
}
}
}

private fun getNearbyBlocks(location: Location, radius: Int): List<Block> {
val blocks: MutableList<Block> = ArrayList()
for (x in location.blockX - radius..location.blockX + radius) {
for (y in location.blockY - radius..location.blockY + radius) {
for (z in location.blockZ - radius..location.blockZ + radius) {
blocks.add(location.getWorld().getBlockAt(x, y, z))
}
}
}
return blocks
}

fun getCustomBlockData(block: Block): Int? {
val data = plugin.storage.getData(AKStorage.CUSTOM_ITEM, block.location.toString()) ?: return null
val data = plugin.storage.getData(AKStorage.ARCHKING_BLOCK, block.location.toString()) ?: return null
return data.asJsonObject.get("data").asString.toIntOrNull()
}

private fun addCustomBlockData(block: Block, customBlock: Int) {
val data = JsonObject()
data.addProperty("data", customBlock.toString())
plugin.storage.addData(AKStorage.CUSTOM_ITEM, block.location.toString(), data)
plugin.storage.setData(AKStorage.ARCHKING_BLOCK, block.location.toString(), data)
}

fun removeCustomBlockData(block: Block) {
plugin.storage.removeData(AKStorage.CUSTOM_ITEM, block.location.toString())
private fun removeCustomBlockData(block: Block) {
plugin.storage.removeData(AKStorage.ARCHKING_BLOCK, block.location.toString())
}
}
Loading

0 comments on commit 9f55cf9

Please sign in to comment.