Skip to content

Commit

Permalink
feat: add allowPassenger town config
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Apr 7, 2024
1 parent f8eec1d commit c653377
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "net.azisaba"
version = "6.9.9"
version = "6.9.10"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/mori01231/lifecore/LifeCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Field> = LazyInitValue {
Class.forName("de.Keyle.MyPet.skill.skills.PickupImpl")
.getDeclaredField("pickup")
.apply { isAccessible = true }
}

fun startTask() {
Bukkit.getScheduler().runTaskTimer(plugin, 20, 20) {
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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")) {
Expand Down

0 comments on commit c653377

Please sign in to comment.