diff --git a/Scenamatica/Scenamatica.iml b/Scenamatica/Scenamatica.iml index ffa8edb13..bf272a60f 100644 --- a/Scenamatica/Scenamatica.iml +++ b/Scenamatica/Scenamatica.iml @@ -5,6 +5,7 @@ + @@ -17,4 +18,4 @@ - \ No newline at end of file + diff --git a/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/minecraft/entity/entities/EntityItemStructure.java b/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/minecraft/entity/entities/EntityItemStructure.java index 52d33ddd8..5a6bb2102 100644 --- a/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/minecraft/entity/entities/EntityItemStructure.java +++ b/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/minecraft/entity/entities/EntityItemStructure.java @@ -4,6 +4,7 @@ import org.kunlab.scenamatica.interfaces.structures.minecraft.entity.EntityStructure; import org.kunlab.scenamatica.interfaces.structures.minecraft.inventory.ItemStackStructure; import org.kunlab.scenamatica.interfaces.scenariofile.Mapped; +import org.kunlab.scenamatica.interfaces.structures.specifiers.PlayerSpecifier; import java.util.UUID; @@ -29,12 +30,12 @@ public interface EntityItemStructure extends EntityStructure, Mapped /** * アイテムを拾ったプレイヤの UUID です。 */ - UUID getOwner(); + PlayerSpecifier getOwner(); /** * アイテムを投げたプレイヤの UUID です。 */ - UUID getThrower(); + PlayerSpecifier getThrower(); /** * アイテムをモブが拾えるかどうかです。 diff --git a/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/specifiers/EntitySpecifier.java b/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/specifiers/EntitySpecifier.java index d360b1613..299dae01c 100644 --- a/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/specifiers/EntitySpecifier.java +++ b/Scenamatica/ScenamaticaModels/src/main/java/org/kunlab/scenamatica/interfaces/structures/specifiers/EntitySpecifier.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Optional; +import java.util.UUID; /** * エンティティの指定子を提供します。 @@ -106,6 +107,18 @@ public interface EntitySpecifier extends Structure */ boolean hasStructure(); + /** + * UUID を持っているかどうか取得します。 + * @return UUID を持っているかどうか + */ + boolean hasUUID(); + + /** + * UUID を取得します。 + * @return UUID + */ + UUID getSelectingUUID(); + /** * ターゲットの構造を取得します。 * diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/LivingEntityStructureImpl.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/LivingEntityStructureImpl.java index f46b3b75d..113a7a9c2 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/LivingEntityStructureImpl.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/LivingEntityStructureImpl.java @@ -390,7 +390,7 @@ public static LivingEntityStructure ofLivingEntity(@NotNull LivingEntity entity) entity.getMaximumNoDamageTicks(), entity.getLastDamage(), entity.getNoDamageTicks(), - entity.getKiller() == null ? PlayerSpecifierImpl.EMPTY: PlayerSpecifierImpl.of(entity.getKiller()), + entity.getKiller() == null ? PlayerSpecifierImpl.EMPTY: PlayerSpecifierImpl.ofPlayer(entity.getKiller()), new ArrayList<>(entity.getActivePotionEffects()), entity.getRemoveWhenFarAway(), entity.getCanPickupItems(), diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/entities/EntityItemStructureImpl.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/entities/EntityItemStructureImpl.java index f836bba9a..ec594aa45 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/entities/EntityItemStructureImpl.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/minecraft/entity/entities/EntityItemStructureImpl.java @@ -2,8 +2,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.kunlab.scenamatica.commons.utils.MapUtils; @@ -12,12 +14,16 @@ import org.kunlab.scenamatica.interfaces.structures.minecraft.entity.EntityStructure; import org.kunlab.scenamatica.interfaces.structures.minecraft.entity.entities.EntityItemStructure; import org.kunlab.scenamatica.interfaces.structures.minecraft.inventory.ItemStackStructure; +import org.kunlab.scenamatica.interfaces.structures.specifiers.EntitySpecifier; +import org.kunlab.scenamatica.interfaces.structures.specifiers.PlayerSpecifier; import org.kunlab.scenamatica.structures.minecraft.entity.EntityStructureImpl; import org.kunlab.scenamatica.structures.minecraft.inventory.ItemStackStructureImpl; +import org.kunlab.scenamatica.structures.specifiers.PlayerSpecifierImpl; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.function.Consumer; @Value @EqualsAndHashCode(callSuper = true) @@ -26,20 +32,18 @@ public class EntityItemStructureImpl extends EntityStructureImpl implements Enti @NotNull ItemStackStructure itemStack; - @Nullable Integer pickupDelay; - @Nullable - UUID owner; - @Nullable - UUID thrower; + @NotNull + EntitySpecifier owner; + @NotNull + EntitySpecifier thrower; Boolean canMobPickup; - Boolean willAge; public EntityItemStructureImpl(@NotNull EntityStructure original, @NotNull ItemStackStructure itemStack, @Nullable Integer pickupDelay, - @Nullable UUID owner, @Nullable UUID thrower, Boolean canMobPickup, Boolean willAge) + @NotNull EntitySpecifier owner, @NotNull EntitySpecifier thrower, Boolean canMobPickup, Boolean willAge) { super(EntityType.DROPPED_ITEM, original); this.itemStack = itemStack; @@ -59,10 +63,10 @@ public static Map serialize(@NotNull EntityItemStructure structu if (structure.getPickupDelay() != null) map.put(KEY_PICKUP_DELAY, structure.getPickupDelay()); - if (structure.getOwner() != null) - map.put(KEY_OWNER, structure.getOwner().toString()); - if (structure.getThrower() != null) - map.put(KEY_THROWER, structure.getThrower().toString()); + if (structure.getOwner().canProvideTarget()) + map.put(KEY_OWNER, structure.getOwner().getTargetRaw()); + if (structure.getThrower().canProvideTarget()) + map.put(KEY_THROWER, structure.getThrower().getTargetRaw()); if (structure.getCanMobPickup() != null) map.put(KEY_CAN_MOB_PICKUP, structure.getCanMobPickup()); if (structure.getWillAge() != null) @@ -89,13 +93,13 @@ public static EntityItemStructure deserialize(@NotNull Map map, Number pickupDelayNum = MapUtils.getAsNumberOrNull(map, KEY_PICKUP_DELAY); Integer pickupDelay = pickupDelayNum != null ? pickupDelayNum.intValue(): null; - UUID ownerUUID = null; + EntitySpecifier owner = null; if (map.containsKey(KEY_OWNER)) - ownerUUID = UUIDUtil.toUUIDOrThrow((String) map.get(KEY_OWNER)); + owner = serializer.tryDeserializeEntitySpecifier(map.get(KEY_OWNER)); - UUID throwerUUID = null; + EntitySpecifier thrower = null; if (map.containsKey(KEY_THROWER)) - throwerUUID = UUIDUtil.toUUIDOrThrow((String) map.get(KEY_THROWER)); + thrower = serializer.tryDeserializeEntitySpecifier(map.get(KEY_THROWER)); ItemStackStructure itemStack = serializer.deserialize(map, ItemStackStructure.class); @@ -109,8 +113,8 @@ public static EntityItemStructure deserialize(@NotNull Map map, EntityStructureImpl.deserialize(copiedMap, serializer), itemStack, pickupDelay, - ownerUUID, - throwerUUID, + owner, + thrower, MapUtils.getOrNull(copiedMap, KEY_CAN_MOB_PICKUP), MapUtils.getOrNull(copiedMap, KEY_WILL_AGE) ); @@ -123,8 +127,8 @@ public static EntityItemStructure of(@NotNull Item entity) EntityStructureImpl.of(entity), ItemStackStructureImpl.of(entity.getItemStack()), entity.getPickupDelay(), - entity.getOwner(), - entity.getThrower(), + PlayerSpecifierImpl.ofPlayer(entity.getOwner()), + PlayerSpecifierImpl.ofPlayer(entity.getThrower()), entity.canMobPickup(), willAge(entity) ); @@ -147,16 +151,26 @@ public void applyTo(Item entity) if (this.pickupDelay != null) entity.setPickupDelay(this.pickupDelay); - if (this.owner != null) - entity.setOwner(this.owner); - if (this.thrower != null) - entity.setThrower(this.thrower); + if (this.owner.canProvideTarget()) + setUUIDByEntitySpecifier(this.owner, entity::setOwner); + if (this.thrower.canProvideTarget()) + setUUIDByEntitySpecifier(this.thrower, entity::setThrower); if (this.canMobPickup != null) entity.setCanMobPickup(this.canMobPickup); if (this.willAge != null) setWillAge(entity, this.willAge); } + private static void setUUIDByEntitySpecifier(@NotNull EntitySpecifier specifier, @NotNull Consumer setter) + { + if (specifier.hasUUID()) + setter.accept(specifier.getSelectingUUID()); + else + specifier.selectTarget(null) + .map(Entity::getUniqueId) + .ifPresent(setter); + } + @Override public boolean canApplyTo(Object target) { diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/EntitySpecifierImpl.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/EntitySpecifierImpl.java index d83f2e29e..7b016c9de 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/EntitySpecifierImpl.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/EntitySpecifierImpl.java @@ -98,6 +98,11 @@ public static EntitySpecifier of(@NotNull E entity) return new EntitySpecifierImpl<>(entity.getUniqueId()); } + public static EntitySpecifierImpl of(@NotNull UUID entityUUID) + { + return new EntitySpecifierImpl<>(entityUUID); + } + protected static UUID tryConvertToUUID(String mayUUID) { try @@ -178,15 +183,26 @@ public Object getTargetRaw() { if (this.selector != null) return this.selector.getOriginal(); - else + else if (this.mayUUID != null) + return this.mayUUID; + else if (this.targetStructure != null) return this.targetStructure; + else + return null; } + @Override public boolean hasUUID() { return this.mayUUID != null; } + @Override + public UUID getSelectingUUID() + { + return this.mayUUID; + } + @Override public boolean canProvideTarget() { diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/PlayerSpecifierImpl.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/PlayerSpecifierImpl.java index 5ff5620bb..376c55d7e 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/PlayerSpecifierImpl.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/main/java/org/kunlab/scenamatica/structures/specifiers/PlayerSpecifierImpl.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -96,9 +97,20 @@ else if (obj instanceof String) throw new IllegalArgumentException("Cannot deserialize PlayerSpecifier from " + obj); } - public static PlayerSpecifier of(@NotNull Player player) + public static PlayerSpecifier ofPlayer(@Nullable Player player) { - return new PlayerSpecifierImpl(player.getUniqueId()); + if (player == null) + return EMPTY; + else + return new PlayerSpecifierImpl(player.getUniqueId()); + } + + public static PlayerSpecifier ofPlayer(@Nullable UUID uuid) + { + if (uuid == null) + return EMPTY; + else + return new PlayerSpecifierImpl(uuid); } @Override diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/entity/EntityItemStructureSerializeTest.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/entity/EntityItemStructureSerializeTest.java index 95755a293..ed0e26325 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/entity/EntityItemStructureSerializeTest.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/entity/EntityItemStructureSerializeTest.java @@ -7,6 +7,8 @@ import org.kunlab.scenamatica.structures.minecraft.inventory.ItemStackStructureSerializeTest; import org.kunlab.scenamatica.structures.minecraft.entity.entities.EntityItemStructureImpl; import org.kunlab.scenamatica.structures.minecraft.utils.MapTestUtil; +import org.kunlab.scenamatica.structures.specifiers.EntitySpecifierImpl; +import org.kunlab.scenamatica.structures.specifiers.PlayerSpecifierImpl; import java.util.HashMap; import java.util.Map; @@ -36,8 +38,8 @@ public class EntityItemStructureSerializeTest AEntityStructureSerializeTest.FULFILLED, ItemStackStructureSerializeTest.FULFILLED, 1, - FULLFILLED_OWNER_UUID, - FULLFILLED_THROWER_UUID, + EntitySpecifierImpl.of(FULLFILLED_OWNER_UUID), + EntitySpecifierImpl.of(FULLFILLED_THROWER_UUID), false, false ); diff --git a/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/inventory/ItemStackStructureSerializeTest.java b/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/inventory/ItemStackStructureSerializeTest.java index 462d496e7..e9faf46b9 100644 --- a/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/inventory/ItemStackStructureSerializeTest.java +++ b/Scenamatica/ScenamaticaStructures/StructureBase/src/test/java/org/kunlab/scenamatica/structures/minecraft/inventory/ItemStackStructureSerializeTest.java @@ -38,15 +38,7 @@ public class ItemStackStructureSerializeTest "This is also a test lore.", "This is literally a test lore." ), - new HashMap() - {{/* - this.put(Enchantment.ARROW_DAMAGE, 1); - this.put(Enchantment.ARROW_FIRE, 1); - this.put(Enchantment.ARROW_INFINITE, 4); - this.put(Enchantment.ARROW_KNOCKBACK, 5); - this.put(Enchantment.LOOT_BONUS_BLOCKS, 1); - this.put(Enchantment.KNOCKBACK, 4);*/ - }}, + new HashMap(), Arrays.asList( ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, diff --git a/Scenamatica/scripts/.gitignore b/Scenamatica/scripts/.gitignore index 2834e7d3e..4ee0353c8 100644 --- a/Scenamatica/scripts/.gitignore +++ b/Scenamatica/scripts/.gitignore @@ -3,3 +3,7 @@ events.json build dist installer +Lib +Scripts + +pyvenv.cfg diff --git a/Scenamatica/scripts/requirements.txt b/Scenamatica/scripts/requirements.txt new file mode 100644 index 000000000..18dd254b2 --- /dev/null +++ b/Scenamatica/scripts/requirements.txt @@ -0,0 +1,2 @@ +pyqt5 +pyinstaller