diff --git a/build.gradle.kts b/build.gradle.kts index b48c37c..7da455d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "net.azisaba" -version = "6.9.9" +version = "6.9.10" java { toolchain.languageVersion.set(JavaLanguageVersion.of(8)) diff --git a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt index b5f844b..691a922 100644 --- a/src/main/java/com/github/mori01231/lifecore/LifeCore.kt +++ b/src/main/java/com/github/mori01231/lifecore/LifeCore.kt @@ -291,7 +291,6 @@ class LifeCore : JavaPlugin() { } catch (e: ClassNotFoundException) { slF4JLogger.warn("Votifier not detected, skipping event listener registration") } - isEnabled try { Class.forName("com.palmergames.bukkit.towny.TownyAPI") pm.registerEvents(TownyOutlawListener(), this) @@ -300,6 +299,7 @@ class LifeCore : JavaPlugin() { .apply { pm.registerEvents(this, this@LifeCore) } } catch (e: ClassNotFoundException) { slF4JLogger.warn("Towny not detected, skipping event listener registration") + e.printStackTrace() } try { Class.forName("net.azisaba.ryuzupluginchat.event.AsyncGlobalMessageEvent") diff --git a/src/main/java/com/github/mori01231/lifecore/config/TownConfig.kt b/src/main/java/com/github/mori01231/lifecore/config/TownConfig.kt index 702fd85..56b329d 100644 --- a/src/main/java/com/github/mori01231/lifecore/config/TownConfig.kt +++ b/src/main/java/com/github/mori01231/lifecore/config/TownConfig.kt @@ -9,6 +9,7 @@ data class TownConfig( @JvmField var allowInvisibility: Boolean = true, @JvmField var allowSit: Boolean = true, @JvmField var allowPetPickup: Boolean = true, + @JvmField var allowPassenger: Boolean = true, ) { companion object { fun getTownConfigAt(lifeCoreConfig: LifeCoreConfig, location: Location): TownConfig? { diff --git a/src/main/java/com/github/mori01231/lifecore/listener/TownSpecificListener.kt b/src/main/java/com/github/mori01231/lifecore/listener/TownSpecificListener.kt index 48e756e..cfe1bf3 100644 --- a/src/main/java/com/github/mori01231/lifecore/listener/TownSpecificListener.kt +++ b/src/main/java/com/github/mori01231/lifecore/listener/TownSpecificListener.kt @@ -2,6 +2,7 @@ package com.github.mori01231.lifecore.listener import com.github.mori01231.lifecore.LifeCore import com.github.mori01231.lifecore.config.TownConfig +import com.github.mori01231.lifecore.util.LazyInitValue import com.github.mori01231.lifecore.util.runTaskTimer import de.Keyle.MyPet.MyPetApi import de.Keyle.MyPet.api.skill.skills.Backpack @@ -15,13 +16,15 @@ import org.bukkit.event.Listener import org.bukkit.event.entity.PotionSplashEvent import org.bukkit.event.player.PlayerCommandPreprocessEvent import org.bukkit.potion.PotionEffectType +import org.spigotmc.event.entity.EntityMountEvent import java.lang.reflect.Field class TownSpecificListener(private val plugin: LifeCore) : Listener { - private val pickupPickupField: Field = + private val pickupPickupField: LazyInitValue = LazyInitValue { Class.forName("de.Keyle.MyPet.skill.skills.PickupImpl") .getDeclaredField("pickup") .apply { isAccessible = true } + } fun startTask() { Bukkit.getScheduler().runTaskTimer(plugin, 20, 20) { @@ -34,6 +37,10 @@ class TownSpecificListener(private val plugin: LifeCore) : Listener { player.removePotionEffect(PotionEffectType.INVISIBILITY) player.sendMessage("${ChatColor.RED}この町での透明化は許可されていません。") } + if (!config.allowPassenger && player.vehicle is Player) { + player.leaveVehicle() + player.sendMessage("${ChatColor.RED}この町でプレイヤーに乗ることは許可されていません。") + } if (Bukkit.getPluginManager().isPluginEnabled("MyPet")) { runMyPet(config, player) } @@ -45,7 +52,7 @@ class TownSpecificListener(private val plugin: LifeCore) : Listener { if (!config.allowPetPickup) { MyPetApi.getMyPetManager().getMyPet(player)?.let { pet -> val skill = pet.skills.get(Pickup::class.java) - if (skill.isActive && pet.skills.isActive(Backpack::class.java) && (pickupPickupField[skill] as Boolean)) { + if (skill.isActive && pet.skills.isActive(Backpack::class.java) && (pickupPickupField.get()[skill] as Boolean)) { player.sendMessage("${ChatColor.RED}この町でのpetpickupは許可されていません。") skill.activate() // this toggles the "pickup" status and sends a message to the player } @@ -67,6 +74,22 @@ class TownSpecificListener(private val plugin: LifeCore) : Listener { } } + @EventHandler + fun onVehicleEnter(e: EntityMountEvent) { + if (e.entity !is Player || e.mount !is Player) { + return + } + val player = e.entity as Player + if (player.hasPermission("lifecore.bypass-town-restrictions")) { + return + } + val config = TownConfig.getTownConfigAt(plugin.lifeCoreConfig, player.location) ?: return + if (!config.allowPassenger) { + e.isCancelled = true + player.sendMessage("${ChatColor.RED}この町でプレイヤーに乗ることは許可されていません。") + } + } + @EventHandler fun onPlayerCommand(e: PlayerCommandPreprocessEvent) { if (e.player.hasPermission("lifecore.bypass-town-restrictions")) {