-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.worldsw.archKing | ||
|
||
import io.papermc.paper.plugin.bootstrap.BootstrapContext | ||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap | ||
import io.papermc.paper.plugin.bootstrap.PluginProviderContext | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
class ArchKingBootstrap: PluginBootstrap { | ||
override fun bootstrap(context: BootstrapContext) { | ||
|
||
} | ||
|
||
override fun createPlugin(context: PluginProviderContext): JavaPlugin { | ||
return ArchKingPlugin() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.worldsw.archKing | ||
|
||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder | ||
import io.papermc.paper.plugin.loader.PluginLoader | ||
|
||
|
||
class ArchKingLoader : PluginLoader { | ||
override fun classloader(classpathBuilder: PluginClasspathBuilder) { | ||
// classpathBuilder.addLibrary(JarLibrary(Path.of("dependency.jar"))) | ||
// val resolver = MavenLibraryResolver() | ||
// resolver.addDependency(Dependency(DefaultArtifact("com.example:example:version"), null)) | ||
// resolver.addRepository( | ||
// RemoteRepository.Builder( | ||
// "paper", | ||
// "default", | ||
// "https://repo.papermc.io/repository/maven-public/" | ||
// ).build() | ||
// ) | ||
// classpathBuilder.addLibrary(resolver) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.worldsw.archKing | ||
|
||
import dev.worldsw.archKing.event.EventHandle | ||
import dev.worldsw.archKing.recipe.ArchKingRecipe | ||
import dev.worldsw.archKing.data.DataManager | ||
import dev.worldsw.archKing.item.ArchKingItem | ||
import dev.worldsw.archKing.rebar.RebarHandler | ||
import org.bukkit.Bukkit | ||
import org.bukkit.event.Listener | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
class ArchKingPlugin: JavaPlugin(), Listener { | ||
lateinit var dataManager: DataManager | ||
lateinit var rebarHandler: RebarHandler | ||
lateinit var itemManager: ArchKingItem | ||
|
||
override fun onEnable() { | ||
rebarHandler = RebarHandler(this) | ||
dataManager = DataManager(this) | ||
|
||
dataManager.init() | ||
itemManager = ArchKingItem(this) | ||
ArchKingRecipe(this) | ||
|
||
server.pluginManager.registerEvents(this, this) | ||
server.pluginManager.registerEvents(EventHandle(this), this) | ||
} | ||
|
||
override fun onDisable() { | ||
Bukkit.getScheduler().cancelTasks(this) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.worldsw.archKing.data | ||
|
||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import com.google.gson.JsonParser | ||
import dev.worldsw.archKing.ArchKingPlugin | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.nio.charset.Charset | ||
|
||
class DataManager(private val plugin: ArchKingPlugin) { | ||
private lateinit var data: JsonObject | ||
private var memory: JsonObject = JsonObject() | ||
|
||
companion object { | ||
const val REBARS = "rebars" | ||
const val CUSTOM_ITEM = "custom_item" | ||
} | ||
|
||
fun init() { | ||
val dataFolder = plugin.dataFolder | ||
if (!dataFolder.exists()) dataFolder.mkdirs() | ||
val dataFile = File(dataFolder, "data.json") | ||
if (!dataFile.exists()) { | ||
dataFile.createNewFile() | ||
dataFile.outputStream().use { fileOutputStream -> | ||
plugin.getResource("data.json")?.copyTo(fileOutputStream) | ||
} | ||
} | ||
data = JsonParser.parseReader(dataFile.reader(Charset.forName("UTF-8"))).asJsonObject | ||
|
||
if (!data.has(REBARS)) { | ||
val rebars = JsonObject() | ||
data.add(REBARS, rebars) | ||
} | ||
if (!data.has(CUSTOM_ITEM)) { | ||
val rebars = JsonObject() | ||
data.add(CUSTOM_ITEM, rebars) | ||
} | ||
} | ||
|
||
fun addData(property: String, inputProperty: String, value: JsonElement) { | ||
getData(property).asJsonObject.add(inputProperty, value) | ||
} | ||
|
||
fun getData(property: String): JsonElement { | ||
return data.get(property) | ||
} | ||
|
||
fun getData(property: String, secondProperty: String): JsonElement? { | ||
return data.get(property).asJsonObject?.get(secondProperty) | ||
} | ||
|
||
fun removeData(property: String, removeProperty: String) { | ||
getData(property).asJsonObject.remove(removeProperty) | ||
} | ||
|
||
fun saveData() { | ||
val dataFile = File(plugin.dataFolder, "data.json") | ||
FileOutputStream(dataFile).close() | ||
dataFile.outputStream().use { fileOutputStream -> | ||
fileOutputStream.write(data.toString().toByteArray(Charset.forName("UTF-8"))) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package dev.worldsw.archKing.event | ||
|
||
import dev.worldsw.archKing.ArchKingPlugin | ||
import dev.worldsw.archKing.data.DataManager | ||
import dev.worldsw.archKing.item.ArchKingItem | ||
import io.papermc.paper.event.block.BlockBreakBlockEvent | ||
import org.bukkit.GameMode | ||
import org.bukkit.Material | ||
import org.bukkit.NamespacedKey | ||
import org.bukkit.Sound | ||
import org.bukkit.block.Block | ||
import org.bukkit.block.BlockFace | ||
import org.bukkit.enchantments.Enchantment | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.block.BlockBreakEvent | ||
import org.bukkit.event.block.BlockPistonExtendEvent | ||
import org.bukkit.event.block.BlockPistonRetractEvent | ||
import org.bukkit.event.block.BlockPlaceEvent | ||
import org.bukkit.event.entity.EntityDamageByEntityEvent | ||
import org.bukkit.event.entity.EntityPickupItemEvent | ||
import org.bukkit.event.world.WorldSaveEvent | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.persistence.PersistentDataType | ||
|
||
|
||
class EventHandle(private val plugin: ArchKingPlugin) : Listener { | ||
private fun rmcToc(block: Block) { | ||
plugin.server.scheduler.scheduleSyncDelayedTask(plugin, { | ||
val dataArchKingItem = plugin.itemManager.getCustomBlockData(block) ?: return@scheduleSyncDelayedTask | ||
if (dataArchKingItem != ArchKingItem.READY_MIXED_CONCRETE) return@scheduleSyncDelayedTask | ||
|
||
plugin.itemManager.removeCustomBlockData(block) | ||
plugin.itemManager.addCustomBlockData(block, ArchKingItem.CONCRETE) | ||
block.type = plugin.itemManager.getItem(ArchKingItem.CONCRETE).type | ||
}, (3600 + (-600..600).random()).toLong()) | ||
} | ||
|
||
@EventHandler | ||
fun onWorldSaveEvent(event: WorldSaveEvent) { | ||
plugin.dataManager.saveData() | ||
} | ||
|
||
@EventHandler | ||
fun onBlockPlaceEvent(event: BlockPlaceEvent) { | ||
if (event.block.type == Material.IRON_BARS) { | ||
plugin.rebarHandler.onPlaceRebar(event.block) | ||
event.isCancelled = true | ||
if (event.player.gameMode != GameMode.CREATIVE) event.player.inventory.removeItem(ItemStack(Material.IRON_BARS)) | ||
} | ||
|
||
val dataArchKingItem = event.itemInHand.itemMeta.persistentDataContainer | ||
.getOrDefault(NamespacedKey(plugin, ArchKingItem.CUSTOM_ITEM), PersistentDataType.INTEGER, ArchKingItem.NOT_CUSTOM_ITEM) | ||
if (dataArchKingItem == ArchKingItem.NOT_CUSTOM_ITEM) return | ||
plugin.itemManager.addCustomBlockData(event.block, dataArchKingItem) | ||
if (dataArchKingItem == ArchKingItem.READY_MIXED_CONCRETE) rmcToc(event.block) | ||
} | ||
|
||
private fun handleBlockMove(block: Block, direction: BlockFace) { | ||
val dataArchKingItem = plugin.itemManager.getCustomBlockData(block) ?: return | ||
plugin.itemManager.removeCustomBlockData(block) | ||
val newBlock = block.getRelative(direction) | ||
plugin.itemManager.addCustomBlockData(newBlock, dataArchKingItem) | ||
} | ||
|
||
@EventHandler | ||
fun onBlockPistonExtendEvent(event: BlockPistonExtendEvent) { | ||
for (block in event.blocks) handleBlockMove(block, event.direction) | ||
} | ||
|
||
@EventHandler | ||
fun onBlockPistonExtendEvent(event: BlockPistonRetractEvent) { | ||
for (block in event.blocks) handleBlockMove(block, event.direction) | ||
} | ||
|
||
@EventHandler | ||
fun onBlockBreakEvent(event: BlockBreakEvent) { | ||
if (!event.isDropItems) return | ||
val dataArchKingItem = plugin.itemManager.getCustomBlockData(event.block) ?: return | ||
plugin.itemManager.removeCustomBlockData(event.block) | ||
|
||
val player = event.player | ||
if (event.player.gameMode == GameMode.CREATIVE) return | ||
|
||
if (!player.inventory.itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) { | ||
val dropItems = plugin.itemManager.getItem(dataArchKingItem, 1) | ||
event.isDropItems = false | ||
event.block.drops.clear() | ||
player.world.dropItemNaturally(event.block.location, dropItems) | ||
} | ||
} | ||
|
||
@EventHandler | ||
fun onBlockBreakBlockEvent(event: BlockBreakBlockEvent) { | ||
if (event.drops.size == 0) return | ||
val dataArchKingItem = plugin.itemManager.getCustomBlockData(event.block) ?: return | ||
plugin.itemManager.removeCustomBlockData(event.block) | ||
|
||
val dropItems = plugin.itemManager.getItem(dataArchKingItem, 1) | ||
event.block.drops.clear() | ||
event.block.world.dropItemNaturally(event.block.location, dropItems) | ||
} | ||
|
||
@EventHandler | ||
fun onEntityPickupItemEvent(event: EntityPickupItemEvent) { | ||
if (event.entity !is Player) return | ||
if (event.item.itemStack.type == Material.AMETHYST_SHARD) event.item.itemStack = plugin.itemManager | ||
.getItem(ArchKingItem.GYPSUM, event.item.itemStack.amount) | ||
} | ||
|
||
@EventHandler | ||
fun onEntityDamageByEntityEvent(event: EntityDamageByEntityEvent) { | ||
if (event.damager !is Player) return | ||
val location = event.entity.location.toBlockLocation().toString() | ||
if (plugin.dataManager.getData(DataManager.REBARS).asJsonObject.has(location)) { | ||
plugin.rebarHandler.onBreakRebar(event.entity) | ||
val player = (event.damager as Player) | ||
player.playSound(event.entity.location, Sound.BLOCK_STONE_BREAK, 1f, 1f) | ||
if (player.gameMode != GameMode.CREATIVE) player.inventory.addItem(ItemStack(Material.IRON_BARS)) | ||
} | ||
} | ||
} |