Add MinionPrePlaceEvent

This commit is contained in:
rudde 2024-04-30 11:59:18 +03:00
parent f90a28e8b0
commit 12773889cd
5 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,10 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -4,7 +4,15 @@
<option name="show" value="ASK" />
<option name="description" value="" />
</component>
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/../javadocs" />
</component>
@ -15,7 +23,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,34 @@
package com.artillexstudios.axminions.api.events
import org.bukkit.entity.Player
import org.bukkit.event.Cancellable
import org.bukkit.event.Event
import org.bukkit.event.HandlerList
class MinionPrePlaceEvent(private val player: Player) : Cancellable, Event() {
companion object {
private val handlerList = HandlerList()
@JvmStatic
fun getHandlerList(): HandlerList = handlerList
}
private var isCancelled = false
override fun getHandlers(): HandlerList {
return MinionPrePlaceEvent.handlerList
}
override fun isCancelled(): Boolean {
return isCancelled
}
fun getPlacer(): Player {
return player
}
override fun setCancelled(cancelled: Boolean) {
isCancelled = cancelled
}
}

View File

@ -20,6 +20,8 @@ import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import org.bukkit.event.block.BlockPlaceEvent
import com.artillexstudios.axminions.api.events.MinionPrePlaceEvent
import org.bukkit.Bukkit
class MinionPlaceListener : Listener {
@ -55,6 +57,12 @@ class MinionPlaceListener : Listener {
}
if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return
val prePlaceEvent = MinionPrePlaceEvent(event.player)
Bukkit.getPluginManager().callEvent(prePlaceEvent)
if(prePlaceEvent.isCancelled) return
meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0)
item.itemMeta = meta