Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import me.ankokunsan.entityPose.EntityPose.Companion.SIZE_KEY
import me.ankokunsan.entityPose.EntityPose.Companion.ZAHYO_KEY
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Color
import org.bukkit.Material
import org.bukkit.Sound
import org.bukkit.attribute.Attribute
import org.bukkit.entity.ArmorStand
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.entity.Tameable
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.PotionMeta
import org.bukkit.persistence.PersistentDataType

object ChooseGUi {
Expand Down Expand Up @@ -153,6 +160,211 @@ object ChooseGUi {
player.playSound(player, Sound.BLOCK_CHEST_OPEN, 1.0f, 2.0f)
}

fun openSettingGUI(player: Player, target: Entity) {
val invs = Bukkit.createInventory(null, 9, "§3エンティティの設定変更")
val living = target as? LivingEntity

val damageItem =
ItemStack(Material.DIAMOND_SWORD).apply {
val meta = itemMeta ?: return@apply
val hasKey =
target.persistentDataContainer.has(EntityPose.INVINCIBLE, PersistentDataType.BYTE)
val status = if (hasKey) "§aON" else "§cOFF"
meta.setDisplayName("§fダメージ無効: $status")
itemMeta = meta
}
val scaleItem1 =
ItemStack(Material.POTION).apply { // LEGACYを消す
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.YELLOW
val scale = living?.getAttribute(Attribute.SCALE)?.baseValue ?: 1.0
meta.setDisplayName("§fサイズ設定(大きくするほう): $scale")
itemMeta = meta
}
val scaleItem2 =
ItemStack(Material.POTION).apply {
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.YELLOW
val scale = living?.getAttribute(Attribute.SCALE)?.baseValue ?: 1.0
meta.setDisplayName("§fサイズ設定(小さくするほう): $scale")
itemMeta = meta
}
val invisibleItem =
ItemStack(Material.POTION).apply {
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.fromRGB(127, 131, 146)
val status = living?.let { if (it.isInvisible) "§aON" else "§cOFF" }
meta.setDisplayName("§f透明: $status")
itemMeta = meta
}
val lockitem =
ItemStack(Material.TRIAL_KEY).apply {
val meta = itemMeta ?: return@apply
val hasKey =
target.persistentDataContainer.has(EntityPose.ARRANGELOCK, PersistentDataType.BYTE)
val lockarrange = if (hasKey) "§aON" else "§cOFF"
meta.setDisplayName("§fアレンジのロック: $lockarrange")
itemMeta = meta
}
if (target is Tameable) {
val tameItem =
ItemStack(Material.BONE).apply {
val meta = itemMeta ?: return@apply
val status = if (target.isTamed) "§aON" else "§cOFF"
meta.setDisplayName("§f懐き状態: $status")
itemMeta = meta
}
invs.setItem(1, tameItem)
} else if (target is ArmorStand) {
val baseItem =
ItemStack(Material.SMOOTH_STONE_SLAB).apply {
val meta = itemMeta ?: return@apply
val status = if (target.hasBasePlate()) "§aON" else "§cOFF"
meta.setDisplayName("§f底のプレート表示: $status")
itemMeta = meta
}
val gravityItem =
ItemStack(Material.ANVIL).apply {
val meta = itemMeta ?: return@apply
val status = if (target.hasGravity()) "§aON" else "§cOFF"
meta.setDisplayName("§f重力: $status")
itemMeta = meta
}
val itemlockItem =
ItemStack(Material.OMINOUS_TRIAL_KEY).apply {
val meta = itemMeta ?: return@apply
val hasKey =
target.persistentDataContainer.has(EntityPose.ITEMLOCK, PersistentDataType.BYTE)
val status = if (hasKey) "§aON" else "§cOFF"
meta.setDisplayName("§fアイテムのロック: $status")
itemMeta = meta
}
invs.setItem(1, gravityItem)
invs.setItem(2, baseItem)
invs.setItem(3, itemlockItem)
}
invs.setItem(0, damageItem)
invs.setItem(5, invisibleItem)
invs.setItem(6, scaleItem1)
invs.setItem(7, scaleItem2)
invs.setItem(8, lockitem)

val filler = getFiller1()
for (i in 0 until invs.size) {
if (invs.getItem(i) == null) invs.setItem(i, filler)
}
player.openInventory(invs)
}

fun openAllSettingGUI(player: Player, targets: List<Entity>) {
val invs = Bukkit.createInventory(null, 9, "§3範囲選択済みエンティティの設定変更")

val damageItem =
ItemStack(Material.DIAMOND_SWORD).apply {
val meta = itemMeta ?: return@apply
val count =
targets.count {
it.persistentDataContainer.has(EntityPose.INVINCIBLE, PersistentDataType.BYTE)
}
meta.setDisplayName("§fダメージ無効 ${count}/${targets.size}体ON")
itemMeta = meta
}
val scaleItem1 =
ItemStack(Material.POTION).apply { // LEGACYを消す
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.YELLOW
meta.setDisplayName("§fスケール設定(大きくするほう)")
val lorelist = mutableListOf<String>()
lorelist.add("§7----- 現在のスケール一覧 -----")
targets.take(10).forEach { target ->
val scale = (target as? LivingEntity)?.getAttribute(Attribute.SCALE)?.baseValue ?: 1.0
val typeName = target.type.name
lorelist.add("§8-$typeName: §b${String.format("%.1f", scale)}")
}
if (targets.size > 10) {
lorelist.add("§8...ほか ${targets.size - 10}体")
}
meta.lore = lorelist
itemMeta = meta
}
val scaleItem2 =
ItemStack(Material.POTION).apply {
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.YELLOW
meta.setDisplayName("§fスケール設定(小さくするほう)")
val lorelist = mutableListOf<String>()
lorelist.add("§7----- 現在のスケール一覧 -----")
targets.take(10).forEach { target ->
val scale = (target as? LivingEntity)?.getAttribute(Attribute.SCALE)?.baseValue ?: 1.0
val typeName = target.type.name
lorelist.add("§8-$typeName: §b${String.format("%.1f", scale)}")
}
if (targets.size > 10) {
lorelist.add("§8...ほか ${targets.size - 10}体")
}
meta.lore = lorelist
itemMeta = meta
}
val invisibleItem =
ItemStack(Material.POTION).apply {
val meta = itemMeta as? PotionMeta ?: return@apply
meta.color = Color.fromRGB(127, 131, 146)
val count = targets.filterIsInstance<LivingEntity>().count { it.isInvisible }
meta.setDisplayName("§f透明: ${count}/${targets.size}体ON")
itemMeta = meta
}
val lockitem =
ItemStack(Material.TRIAL_KEY).apply {
val meta = itemMeta ?: return@apply
val count =
targets.count {
it.persistentDataContainer.has(EntityPose.ARRANGELOCK, PersistentDataType.BYTE)
}
meta.setDisplayName("§fアレンジのロック ${count}/${targets.size}体ON")
itemMeta = meta
}

if (targets.all { it is ArmorStand }) {
val baseItem =
ItemStack(Material.SMOOTH_STONE_SLAB).apply {
val meta = itemMeta ?: return@apply
val count = targets.filterIsInstance<ArmorStand>().count { it.hasBasePlate() }
meta.setDisplayName("§f底のプレート表示: ${count}/${targets.size}体ON")
itemMeta = meta
}
val gravityItem =
ItemStack(Material.ANVIL).apply {
val meta = itemMeta ?: return@apply
val count = targets.count { it.hasGravity() }
meta.setDisplayName("§f重力: ${count}/${targets.size}体ON")
itemMeta = meta
}
val itemlockItem =
ItemStack(Material.OMINOUS_TRIAL_KEY).apply {
val meta = itemMeta ?: return@apply
val count =
targets.count {
it.persistentDataContainer.has(EntityPose.ITEMLOCK, PersistentDataType.BYTE)
}
meta.setDisplayName("§fアイテムのロック: ${count}/${targets.size}体ON")
itemMeta = meta
}
invs.setItem(1, gravityItem)
invs.setItem(2, baseItem)
invs.setItem(3, itemlockItem)
}
invs.setItem(0, damageItem)
invs.setItem(5, invisibleItem)
invs.setItem(6, scaleItem1)
invs.setItem(7, scaleItem2)
invs.setItem(8, lockitem)
val filler = getFiller1()
for (i in 0 until invs.size) {
if (invs.getItem(i) == null) invs.setItem(i, filler)
}
player.openInventory(invs)
}

private fun getFiller1(): ItemStack {
return ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE).apply {
itemMeta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.ankokunsan.entityPose

import java.util.UUID
import kotlin.collections.filter
import kotlin.math.roundToInt
import me.ankokunsan.entityPose.EntityCopyClick.Companion.activeselection
import me.ankokunsan.entityPose.EntityCopyClick.Companion.selection
import me.ankokunsan.entityPose.EntityPose.Companion.CAT_KEY
Expand All @@ -15,7 +14,6 @@ import net.md_5.bungee.api.ChatMessageType
import net.md_5.bungee.api.chat.TextComponent
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.Sound
import org.bukkit.entity.ArmorStand
Expand All @@ -29,6 +27,7 @@ import org.bukkit.event.block.Action
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.player.PlayerArmorStandManipulateEvent
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerInteractAtEntityEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerItemHeldEvent
Expand Down Expand Up @@ -124,6 +123,37 @@ class EntityClick : Listener {
}
}

@EventHandler
fun onDropEvent(event: PlayerDropItemEvent) {
val player = event.player
val item = event.itemDrop.itemStack
if (!isEntiStick(item)) return
if (!player.hasPermission("entitypose_arrange")) return
if (!player.isSneaking) return
event.isCancelled = true
val result =
player.world.rayTraceEntities(player.eyeLocation, player.location.direction, 3.0, 0.1) {
it != player
}
val target = result?.hitEntity ?: return
if (target is Player) {
player.sendMessage("§6[EntityPose] §cプレイヤーの情報を見たり、いじろうとしないでね")
return
}
if (target is LivingEntity && target.hasAI()) {
player.sendMessage("§6[EntityPose] §cこのモブはAIが有効です")
return
}
val selected = activeselection[player.uniqueId]
if (selected != null && selected.contains(target)) {
val targets = selected.filter { it.isValid }
ChooseGUi.openAllSettingGUI(player, targets)
} else {
ChooseGUi.openSettingGUI(player, target)
return
}
}

@EventHandler
fun onLeftClickBlock(event: PlayerInteractEvent) {
val player = event.player
Expand Down Expand Up @@ -597,22 +627,6 @@ class EntityClick : Listener {
// 叩いた対象が、今追従させているものと一致する場合のみ実行
if (currentPreview != entity) return
event.isCancelled = true

val loc = entity.location
val directionToPlayer = player.eyeLocation.toVector().subtract(loc.toVector())
val lookAtYaw = loc.clone().setDirection(directionToPlayer).yaw
val snappedYaw = ((lookAtYaw / 45.0).roundToInt() * 45.0).toFloat()

val gridLoc =
Location(
loc.world,
loc.blockX + 0.5, // X軸の真ん中
loc.blockY.toDouble(), // 高さはそのまま(空中可)
loc.blockZ + 0.5, // Z軸の真ん中
snappedYaw,
0f // 垂直に向かせる
)
entity.teleport(gridLoc)
entity.setGravity(false)

player.sendMessage("§6[EntityPose] §aエンティティを固定しました!")
Expand Down
Loading
Loading