fixing building hint problems
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package com.pobnellion.aoe
|
package com.pobnellion.aoe
|
||||||
|
|
||||||
import com.pobnellion.aoe.command.TestCommand
|
import com.pobnellion.aoe.command.TestCommand
|
||||||
|
import com.pobnellion.aoe.command.TestTabCompleter
|
||||||
import com.pobnellion.aoe.team.Team
|
import com.pobnellion.aoe.team.Team
|
||||||
import com.pobnellion.aoe.ui.PlaceHint
|
import com.pobnellion.aoe.ui.PlaceHint
|
||||||
import com.pobnellion.aoe.ui.PlaceItem
|
import com.pobnellion.aoe.ui.PlaceItem
|
||||||
@ -8,6 +9,7 @@ import org.bukkit.Bukkit
|
|||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
class Aoe : JavaPlugin() {
|
class Aoe : JavaPlugin() {
|
||||||
companion object {
|
companion object {
|
||||||
@ -18,7 +20,8 @@ class Aoe : JavaPlugin() {
|
|||||||
return teams.singleOrNull() { team -> team.players.contains(player) }
|
return teams.singleOrNull() { team -> team.players.contains(player) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSchematicsFolder(): File = File(instance!!.dataFolder, "schematics")
|
fun getSchematicFile(schematicName: String): File =
|
||||||
|
Paths.get(instance!!.dataFolder.path, "schematics", "$schematicName.schem").toFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
@ -29,7 +32,8 @@ class Aoe : JavaPlugin() {
|
|||||||
Bukkit.getPluginManager().registerEvents(PlaceHint, this)
|
Bukkit.getPluginManager().registerEvents(PlaceHint, this)
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
this.getCommand("debug")!!.setExecutor(TestCommand())
|
this.getCommand("aoe")!!.setExecutor(TestCommand())
|
||||||
|
this.getCommand("aoe")!!.tabCompleter = TestTabCompleter()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisable() {
|
override fun onDisable() {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.pobnellion.aoe.building
|
package com.pobnellion.aoe.building
|
||||||
|
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
import org.bukkit.entity.Player
|
|
||||||
|
|
||||||
abstract class Building(val location: Location, val variant: Int) {
|
abstract class Building(val location: Location, val variant: Int) {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
package com.pobnellion.aoe.building
|
package com.pobnellion.aoe.building
|
||||||
|
|
||||||
enum class BuildingType {
|
enum class BuildingType {
|
||||||
|
ARCHERY_RANGE,
|
||||||
BARRACKS,
|
BARRACKS,
|
||||||
|
DOCK,
|
||||||
FARM,
|
FARM,
|
||||||
HOUSE,
|
HOUSE,
|
||||||
|
LUMBER_CAMP,
|
||||||
MILL,
|
MILL,
|
||||||
|
MINING_CAMP,
|
||||||
|
STABLE,
|
||||||
TOWN_CENTER,
|
TOWN_CENTER,
|
||||||
UNIQUE,
|
UNIQUE,
|
||||||
WALL,
|
WALL,
|
||||||
|
|||||||
51
src/main/kotlin/com/pobnellion/aoe/building/TownCenter.kt
Normal file
51
src/main/kotlin/com/pobnellion/aoe/building/TownCenter.kt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package com.pobnellion.aoe.building
|
||||||
|
|
||||||
|
import com.pobnellion.aoe.Aoe
|
||||||
|
import com.pobnellion.aoe.ui.PlaceHintValidators
|
||||||
|
import com.sk89q.worldedit.WorldEdit
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.Clipboard
|
||||||
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats
|
||||||
|
import com.sk89q.worldedit.function.operation.Operation
|
||||||
|
import com.sk89q.worldedit.function.operation.Operations
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3
|
||||||
|
import com.sk89q.worldedit.session.ClipboardHolder
|
||||||
|
import com.sk89q.worldedit.world.World
|
||||||
|
import org.bukkit.Location
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
|
||||||
|
|
||||||
|
class TownCenter(location: Location, variant: Int): Building(location, variant) {
|
||||||
|
companion object Info: BuildingInfo {
|
||||||
|
override val buildingType: BuildingType = BuildingType.TOWN_CENTER
|
||||||
|
override val schematicNames: List<String> = listOf("plains_towncenter")
|
||||||
|
|
||||||
|
override fun validate(location: Location): Boolean {
|
||||||
|
return PlaceHintValidators.allReplaceable(location, 10f, 10f, 10f, -2)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun create(location: Location, variant: Int): Building {
|
||||||
|
return TownCenter(location, variant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
var clipboard: Clipboard
|
||||||
|
|
||||||
|
val file: File = Aoe.getSchematicFile(schematicNames[variant])
|
||||||
|
val format = ClipboardFormats.findByFile(file)
|
||||||
|
format!!.getReader(FileInputStream(file)).use { reader ->
|
||||||
|
clipboard = reader.read()
|
||||||
|
}
|
||||||
|
|
||||||
|
clipboard.origin = BlockVector3.ZERO
|
||||||
|
|
||||||
|
WorldEdit.getInstance().newEditSession(location.world as World).use { editSession ->
|
||||||
|
val operation: Operation = ClipboardHolder(clipboard)
|
||||||
|
.createPaste(editSession)
|
||||||
|
.to(BlockVector3.at(location.x, location.y, location.z)) // configure here
|
||||||
|
.build()
|
||||||
|
Operations.complete(operation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,11 @@
|
|||||||
package com.pobnellion.aoe.command
|
package com.pobnellion.aoe.command
|
||||||
|
|
||||||
import com.pobnellion.aoe.entity.AoeVillager
|
import com.pobnellion.aoe.Aoe
|
||||||
|
import com.pobnellion.aoe.team.Plains
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.command.TabCompleter
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
class TestCommand : CommandExecutor {
|
class TestCommand : CommandExecutor {
|
||||||
@ -13,7 +15,42 @@ class TestCommand : CommandExecutor {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val player: Player = sender
|
if (args.isEmpty()) {
|
||||||
|
sender.sendMessage("invalid command")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when (args[0]) {
|
||||||
|
"team" -> team(sender, args)
|
||||||
|
else -> sender.sendMessage("Invalid argument: ${args[0]}")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun team(sender: CommandSender, args: Array<out String>) {
|
||||||
|
if (args.size == 1) {
|
||||||
|
sender.sendMessage("please provide a team")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
when (args[1]) {
|
||||||
|
"plains" -> Aoe.teams.add(Plains(listOf(sender as Player)))
|
||||||
|
else -> sender.sendMessage("Invalid team: ${args[1]}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestTabCompleter: TabCompleter {
|
||||||
|
override fun onTabComplete(sender: CommandSender, command: Command, label: String, args: Array<out String>): MutableList<String>? {
|
||||||
|
val options: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
|
if (args.size == 1)
|
||||||
|
options.add("team")
|
||||||
|
|
||||||
|
if (args.size == 2)
|
||||||
|
options.add("plains")
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -3,17 +3,24 @@ package com.pobnellion.aoe.team
|
|||||||
import com.pobnellion.aoe.building.BuildingInfo
|
import com.pobnellion.aoe.building.BuildingInfo
|
||||||
import com.pobnellion.aoe.building.BuildingType
|
import com.pobnellion.aoe.building.BuildingType
|
||||||
import com.pobnellion.aoe.building.House
|
import com.pobnellion.aoe.building.House
|
||||||
|
import com.pobnellion.aoe.building.TownCenter
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
class Plains(players: List<Player>) : Team(players) {
|
class Plains(players: List<Player>) : Team(players) {
|
||||||
|
override val name: String = "Plains"
|
||||||
|
|
||||||
override fun getBuildingInfo(type: BuildingType): BuildingInfo {
|
override fun getBuildingInfo(type: BuildingType): BuildingInfo {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
|
BuildingType.ARCHERY_RANGE -> TODO()
|
||||||
BuildingType.BARRACKS -> TODO()
|
BuildingType.BARRACKS -> TODO()
|
||||||
|
BuildingType.DOCK -> TODO()
|
||||||
BuildingType.FARM -> TODO()
|
BuildingType.FARM -> TODO()
|
||||||
BuildingType.HOUSE -> House.Info
|
BuildingType.HOUSE -> House.Info
|
||||||
|
BuildingType.LUMBER_CAMP -> TODO()
|
||||||
BuildingType.MILL -> TODO()
|
BuildingType.MILL -> TODO()
|
||||||
BuildingType.TOWN_CENTER -> TODO()
|
BuildingType.MINING_CAMP -> TODO()
|
||||||
|
BuildingType.STABLE -> TODO()
|
||||||
|
BuildingType.TOWN_CENTER -> TownCenter.Info
|
||||||
BuildingType.UNIQUE -> TODO()
|
BuildingType.UNIQUE -> TODO()
|
||||||
BuildingType.WALL -> TODO()
|
BuildingType.WALL -> TODO()
|
||||||
BuildingType.WATCH_TOWER -> TODO()
|
BuildingType.WATCH_TOWER -> TODO()
|
||||||
|
|||||||
@ -9,9 +9,14 @@ import org.bukkit.entity.Player
|
|||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
abstract class Team(val players: List<Player>) {
|
abstract class Team(val players: List<Player>) {
|
||||||
val buildings: MutableList<Building> = mutableListOf()
|
private val buildings: MutableList<Building> = mutableListOf()
|
||||||
|
|
||||||
|
init {
|
||||||
|
players.forEach { player -> player.sendMessage("Joined team $name") }
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun getBuildingInfo(type: BuildingType): BuildingInfo
|
protected abstract fun getBuildingInfo(type: BuildingType): BuildingInfo
|
||||||
|
protected abstract val name: String
|
||||||
|
|
||||||
fun addBuilding(location: Location, building: BuildingInfo, variant: Int) {
|
fun addBuilding(location: Location, building: BuildingInfo, variant: Int) {
|
||||||
buildings.add(building.create(location, variant))
|
buildings.add(building.create(location, variant))
|
||||||
|
|||||||
@ -40,8 +40,7 @@ class BuildingPlaceHint(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val schematicName = buildingInfo.schematicNames[buildingVariant]
|
val schematicName = buildingInfo.schematicNames[buildingVariant]
|
||||||
val file = File(Aoe.getSchematicsFolder(),
|
val file = Aoe.getSchematicFile(schematicName)
|
||||||
if (schematicName.endsWith(".schem")) schematicName else "$schematicName.schem")
|
|
||||||
|
|
||||||
val format = ClipboardFormats.findByFile(file)
|
val format = ClipboardFormats.findByFile(file)
|
||||||
val reader = format?.getReader(FileInputStream(file))
|
val reader = format?.getReader(FileInputStream(file))
|
||||||
@ -51,7 +50,8 @@ class BuildingPlaceHint(
|
|||||||
|
|
||||||
this.offset = Vector(
|
this.offset = Vector(
|
||||||
-floor(clipboard.dimensions.x() / 2.0),
|
-floor(clipboard.dimensions.x() / 2.0),
|
||||||
clipboard.minY.toDouble(),
|
// clipboard.minY.toDouble(),
|
||||||
|
0.0,
|
||||||
-floor(clipboard.dimensions.z() / 2.0))
|
-floor(clipboard.dimensions.z() / 2.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class BuildingPlaceHint(
|
|||||||
|
|
||||||
if (!block.material.isAir && !block.material.isEmpty) {
|
if (!block.material.isAir && !block.material.isEmpty) {
|
||||||
val x = (blockPosition.x() - schematic.minimumPoint.x()).toFloat()
|
val x = (blockPosition.x() - schematic.minimumPoint.x()).toFloat()
|
||||||
val y = blockPosition.y().toFloat()
|
val y = (blockPosition.y() - schematic.minimumPoint.y()).toFloat()
|
||||||
val z = (blockPosition.z() - schematic.minimumPoint.z()).toFloat()
|
val z = (blockPosition.z() - schematic.minimumPoint.z()).toFloat()
|
||||||
|
|
||||||
displayIds.add(spawnBlockDisplay(initialLocation, block, offset = Vector3f(x, y, z), options = 0b01000000))
|
displayIds.add(spawnBlockDisplay(initialLocation, block, offset = Vector3f(x, y, z), options = 0b01000000))
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketContainer
|
|||||||
import com.comphenix.protocol.wrappers.*
|
import com.comphenix.protocol.wrappers.*
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry
|
||||||
import com.destroystokyo.paper.MaterialSetTag
|
import com.destroystokyo.paper.MaterialSetTag
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
import org.bukkit.block.data.BlockData
|
import org.bukkit.block.data.BlockData
|
||||||
import org.bukkit.entity.EntityType
|
import org.bukkit.entity.EntityType
|
||||||
@ -59,6 +60,7 @@ abstract class PlaceHint {
|
|||||||
return
|
return
|
||||||
|
|
||||||
val target = event.player.getTargetBlockExact(MAX_TARGET_DISTANCE)
|
val target = event.player.getTargetBlockExact(MAX_TARGET_DISTANCE)
|
||||||
|
|
||||||
val block = if (target == null) null else event.player.getTargetBlock(MaterialSetTag.REPLACEABLE.values, MAX_TARGET_DISTANCE)
|
val block = if (target == null) null else event.player.getTargetBlock(MaterialSetTag.REPLACEABLE.values, MAX_TARGET_DISTANCE)
|
||||||
playerHints[event.player.uniqueId]!!.moveTo(block?.location)
|
playerHints[event.player.uniqueId]!!.moveTo(block?.location)
|
||||||
}
|
}
|
||||||
@ -107,7 +109,7 @@ abstract class PlaceHint {
|
|||||||
protected abstract fun confirm()
|
protected abstract fun confirm()
|
||||||
protected abstract fun validate(location: Location): Boolean
|
protected abstract fun validate(location: Location): Boolean
|
||||||
|
|
||||||
protected fun show(initialLocation: Location) {
|
private fun show(initialLocation: Location) {
|
||||||
initialLocation.add(this.offset)
|
initialLocation.add(this.offset)
|
||||||
currentLocation = initialLocation
|
currentLocation = initialLocation
|
||||||
|
|
||||||
@ -160,7 +162,7 @@ abstract class PlaceHint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (currentLocation == null) {
|
if (currentLocation == null) {
|
||||||
addDisplays(newLocation)
|
show(newLocation)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +236,7 @@ abstract class PlaceHint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected open fun updateColour() {
|
protected open fun updateColour() {
|
||||||
// outline
|
// outline glow
|
||||||
val outlineTeamPacket = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM)
|
val outlineTeamPacket = PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM)
|
||||||
outlineTeamPacket.strings.write(0, "placeValid")
|
outlineTeamPacket.strings.write(0, "placeValid")
|
||||||
outlineTeamPacket.integers.write(0, 2)
|
outlineTeamPacket.integers.write(0, 2)
|
||||||
|
|||||||
@ -36,6 +36,9 @@ class PlaceItem : Listener {
|
|||||||
if (event.material != Material.BRICKS)
|
if (event.material != Material.BRICKS)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if (Aoe.getTeam(event.player) == null)
|
||||||
|
return
|
||||||
|
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
event.player.openInventory(buildingInventory)
|
event.player.openInventory(buildingInventory)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,6 @@ depend:
|
|||||||
- ProtocolLib
|
- ProtocolLib
|
||||||
- WorldEdit
|
- WorldEdit
|
||||||
commands:
|
commands:
|
||||||
debug:
|
aoe:
|
||||||
description: Debug command
|
description: Debug command
|
||||||
usage: /debug
|
usage: /aoe
|
||||||
|
|||||||
Reference in New Issue
Block a user