mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-29 12:45:18 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2e5b9aa94a
10
.idea/codeStyles/Project.xml
Normal file
10
.idea/codeStyles/Project.xml
Normal 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>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
@ -4,7 +4,15 @@
|
|||||||
<option name="show" value="ASK" />
|
<option name="show" value="ASK" />
|
||||||
<option name="description" value="" />
|
<option name="description" value="" />
|
||||||
</component>
|
</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="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
<component name="JavadocGenerationManager">
|
<component name="JavadocGenerationManager">
|
||||||
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/../javadocs" />
|
<option name="OUTPUT_DIRECTORY" value="$PROJECT_DIR$/../javadocs" />
|
||||||
</component>
|
</component>
|
||||||
@ -15,7 +23,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.artillexstudios.axminions.api.events
|
||||||
|
|
||||||
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
|
import org.bukkit.block.Block
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.Cancellable
|
||||||
|
import org.bukkit.event.HandlerList
|
||||||
|
|
||||||
|
class MinionChestLinkEvent(minion: Minion, private val player: Player, private val block: Block) : MinionEvent(minion), Cancellable {
|
||||||
|
companion object {
|
||||||
|
private val handlerList = HandlerList()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getHandlerList(): HandlerList = handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
private var failMessage: String? = null
|
||||||
|
|
||||||
|
override fun getHandlers(): HandlerList {
|
||||||
|
return handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLinker(): Player {
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getFailMessage(): String? {
|
||||||
|
return failMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setFailMessage(message: String) {
|
||||||
|
failMessage = message
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBlock(): Block {
|
||||||
|
return block
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCancelled(): Boolean {
|
||||||
|
return isCancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCancelled(cancelled: Boolean) {
|
||||||
|
isCancelled = cancelled
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.artillexstudios.axminions.api.events
|
||||||
|
|
||||||
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.Cancellable
|
||||||
|
import org.bukkit.event.HandlerList
|
||||||
|
|
||||||
|
class PreMinionPickupEvent(private val player: Player, minion: Minion) : MinionEvent(minion), Cancellable {
|
||||||
|
companion object {
|
||||||
|
private val handlerList = HandlerList()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getHandlerList(): HandlerList = handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
|
||||||
|
override fun getHandlers(): HandlerList {
|
||||||
|
return PreMinionPickupEvent.handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPlayer(): Player {
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCancelled(): Boolean {
|
||||||
|
return isCancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCancelled(cancelled: Boolean) {
|
||||||
|
isCancelled = cancelled
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.artillexstudios.axminions.api.events
|
||||||
|
|
||||||
|
import org.bukkit.Location
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.Cancellable
|
||||||
|
import org.bukkit.event.Event
|
||||||
|
import org.bukkit.event.HandlerList
|
||||||
|
|
||||||
|
class PreMinionPlaceEvent(private val player: Player, private val location: Location) : Cancellable, Event() {
|
||||||
|
companion object {
|
||||||
|
private val handlerList = HandlerList()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getHandlerList(): HandlerList = handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isCancelled = false
|
||||||
|
private var shouldOverridePlayerLimit = false
|
||||||
|
|
||||||
|
override fun getHandlers(): HandlerList {
|
||||||
|
return PreMinionPlaceEvent.handlerList
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isCancelled(): Boolean {
|
||||||
|
return isCancelled
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPlacer(): Player {
|
||||||
|
return player
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLocation(): Location {
|
||||||
|
return location
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getShouldOverridePlayerLimit(): Boolean {
|
||||||
|
return shouldOverridePlayerLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setShouldOverridePlayerLimit(should: Boolean) {
|
||||||
|
shouldOverridePlayerLimit = should
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCancelled(cancelled: Boolean) {
|
||||||
|
isCancelled = cancelled
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,13 @@ import com.artillexstudios.axapi.utils.StringUtils
|
|||||||
import com.artillexstudios.axminions.AxMinionsPlugin
|
import com.artillexstudios.axminions.AxMinionsPlugin
|
||||||
import com.artillexstudios.axminions.api.config.Config
|
import com.artillexstudios.axminions.api.config.Config
|
||||||
import com.artillexstudios.axminions.api.config.Messages
|
import com.artillexstudios.axminions.api.config.Messages
|
||||||
|
import com.artillexstudios.axminions.api.events.MinionChestLinkEvent
|
||||||
|
import com.artillexstudios.axminions.api.events.PreMinionDamageEntityEvent
|
||||||
import com.artillexstudios.axminions.api.minions.Minion
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import java.util.WeakHashMap
|
import java.util.WeakHashMap
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.entity.LivingEntity
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
@ -26,6 +30,18 @@ class LinkingListener : Listener {
|
|||||||
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
|
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
|
||||||
|
|
||||||
val minion = linking.remove(event.player) ?: return
|
val minion = linking.remove(event.player) ?: return
|
||||||
|
|
||||||
|
val linkEvent = MinionChestLinkEvent(
|
||||||
|
minion,
|
||||||
|
event.player,
|
||||||
|
event.clickedBlock!!
|
||||||
|
)
|
||||||
|
Bukkit.getPluginManager().callEvent(linkEvent)
|
||||||
|
if (linkEvent.isCancelled) {
|
||||||
|
event.player.sendMessage(StringUtils.formatToString(linkEvent.getFailMessage() ?: (Messages.PREFIX() + Messages.LINK_FAIL())))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
if (minion.getLocation()
|
if (minion.getLocation()
|
||||||
.distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE()
|
.distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE()
|
||||||
|
@ -20,6 +20,8 @@ import org.bukkit.event.player.PlayerInteractEvent
|
|||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
import org.bukkit.event.block.BlockPlaceEvent
|
import org.bukkit.event.block.BlockPlaceEvent
|
||||||
|
import com.artillexstudios.axminions.api.events.PreMinionPlaceEvent
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
|
||||||
class MinionPlaceListener : Listener {
|
class MinionPlaceListener : Listener {
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ class MinionPlaceListener : Listener {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val prePlaceEvent = PreMinionPlaceEvent(event.player, event.clickedBlock!!.location)
|
||||||
|
|
||||||
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
|
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
|
||||||
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
|
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
|
||||||
val charge = meta.persistentDataContainer.get(Keys.CHARGE, PersistentDataType.LONG) ?: 0
|
val charge = meta.persistentDataContainer.get(Keys.CHARGE, PersistentDataType.LONG) ?: 0
|
||||||
@ -55,6 +59,10 @@ class MinionPlaceListener : Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return
|
if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(prePlaceEvent)
|
||||||
|
if (prePlaceEvent.isCancelled) return
|
||||||
|
|
||||||
meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0)
|
meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0)
|
||||||
item.itemMeta = meta
|
item.itemMeta = meta
|
||||||
|
|
||||||
@ -63,10 +71,11 @@ class MinionPlaceListener : Listener {
|
|||||||
val maxMinions = AxMinionsAPI.INSTANCE.getMinionLimit(event.player)
|
val maxMinions = AxMinionsAPI.INSTANCE.getMinionLimit(event.player)
|
||||||
|
|
||||||
val chunk = location.chunk
|
val chunk = location.chunk
|
||||||
|
|
||||||
AxMinionsPlugin.dataQueue.submit {
|
AxMinionsPlugin.dataQueue.submit {
|
||||||
val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId)
|
val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId)
|
||||||
|
|
||||||
if (placed >= maxMinions && !event.player.hasPermission("axminions.limit.*")) {
|
if (placed >= maxMinions && !prePlaceEvent.getShouldOverridePlayerLimit() && !event.player.hasPermission("axminions.limit.*")) {
|
||||||
event.player.sendMessage(
|
event.player.sendMessage(
|
||||||
StringUtils.formatToString(
|
StringUtils.formatToString(
|
||||||
Messages.PREFIX() + Messages.PLACE_LIMIT_REACHED(),
|
Messages.PREFIX() + Messages.PLACE_LIMIT_REACHED(),
|
||||||
|
@ -16,6 +16,7 @@ import com.artillexstudios.axminions.AxMinionsPlugin
|
|||||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||||
import com.artillexstudios.axminions.api.config.Config
|
import com.artillexstudios.axminions.api.config.Config
|
||||||
import com.artillexstudios.axminions.api.config.Messages
|
import com.artillexstudios.axminions.api.config.Messages
|
||||||
|
import com.artillexstudios.axminions.api.events.PreMinionPickupEvent
|
||||||
import com.artillexstudios.axminions.api.minions.Direction
|
import com.artillexstudios.axminions.api.minions.Direction
|
||||||
import com.artillexstudios.axminions.api.minions.Minion
|
import com.artillexstudios.axminions.api.minions.Minion
|
||||||
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
|
||||||
@ -39,7 +40,6 @@ import org.bukkit.block.Container
|
|||||||
import org.bukkit.enchantments.Enchantment
|
import org.bukkit.enchantments.Enchantment
|
||||||
import org.bukkit.entity.EntityType
|
import org.bukkit.entity.EntityType
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.CreativeCategory
|
|
||||||
import org.bukkit.inventory.Inventory
|
import org.bukkit.inventory.Inventory
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.Damageable
|
import org.bukkit.inventory.meta.Damageable
|
||||||
@ -164,6 +164,10 @@ class Minion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun breakMinion(event: PacketEntityInteractEvent) {
|
private fun breakMinion(event: PacketEntityInteractEvent) {
|
||||||
|
val preBreakEvent = PreMinionPickupEvent(event.player, this)
|
||||||
|
Bukkit.getPluginManager().callEvent(preBreakEvent)
|
||||||
|
if (preBreakEvent.isCancelled) return
|
||||||
|
|
||||||
LinkingListener.linking.remove(event.player)
|
LinkingListener.linking.remove(event.player)
|
||||||
remove()
|
remove()
|
||||||
setTicking(false)
|
setTicking(false)
|
||||||
|
Loading…
Reference in New Issue
Block a user