From 7c14c513404027d341017e75af0d972b7ffe59e4 Mon Sep 17 00:00:00 2001 From: Lee Date: Thu, 28 Sep 2023 18:19:46 -0700 Subject: [PATCH] added Collar option --- .../lee/code/pets/enums/DyeColorChatColor.java | 4 +--- .../menu/menudata/options/OptionSelector.java | 2 +- .../lee/code/pets/pets/pet/animal/CatPet.java | 6 ++++-- .../java/lee/code/pets/utils/PetDataUtil.java | 15 +++++++++------ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/lee/code/pets/enums/DyeColorChatColor.java b/src/main/java/lee/code/pets/enums/DyeColorChatColor.java index 01d7816..b298701 100644 --- a/src/main/java/lee/code/pets/enums/DyeColorChatColor.java +++ b/src/main/java/lee/code/pets/enums/DyeColorChatColor.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; -import org.bukkit.DyeColor; @AllArgsConstructor public enum DyeColorChatColor { @@ -21,8 +20,7 @@ public enum DyeColorChatColor { ORANGE("&#FFA500"), MAGENTA("&#FF00FF"), LIGHT_BLUE("&#ADD8E6"), - YELLOW("&e"), - + YELLOW("&e") ; @Getter private String color; } diff --git a/src/main/java/lee/code/pets/menus/menu/menudata/options/OptionSelector.java b/src/main/java/lee/code/pets/menus/menu/menudata/options/OptionSelector.java index 4d5e25f..daf3606 100644 --- a/src/main/java/lee/code/pets/menus/menu/menudata/options/OptionSelector.java +++ b/src/main/java/lee/code/pets/menus/menu/menudata/options/OptionSelector.java @@ -12,7 +12,7 @@ public enum OptionSelector { BAT(new String[] {Option.NAME.name()}), BEE(new String[] {Option.NAME.name(), Option.BABY.name(), Option.ANGRY.name(), Option.NECTAR.name(), Option.STUNG.name()}), CAMEL(new String[] {Option.NAME.name(), Option.BABY.name(), Option.SADDLE.name()}), - CAT(new String[] {Option.NAME.name(), Option.BABY.name(), Option.VARIANT.name(), Option.COLOR.name()}), + CAT(new String[] {Option.NAME.name(), Option.BABY.name(), Option.VARIANT.name(), Option.COLLAR.name(), Option.COLOR.name()}), CHICKEN(new String[] {Option.NAME.name(), Option.BABY.name()}), DONKEY(new String[] {Option.NAME.name(), Option.BABY.name(), Option.CHEST.name(), Option.SADDLE.name()}), FOX(new String[] {Option.NAME.name(), Option.BABY.name(), Option.VARIANT.name()}), diff --git a/src/main/java/lee/code/pets/pets/pet/animal/CatPet.java b/src/main/java/lee/code/pets/pets/pet/animal/CatPet.java index 506e374..90995aa 100644 --- a/src/main/java/lee/code/pets/pets/pet/animal/CatPet.java +++ b/src/main/java/lee/code/pets/pets/pet/animal/CatPet.java @@ -23,14 +23,16 @@ public CatPet(Player player, String[] data) { setCustomNameVisible(true); setPersistenceRequired(true); setCanPickUpLoot(false); - setTame(true); setMaxUpStep(1.0F); collides = false; ageLocked = true; setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(data[1]))); setBaby(Boolean.parseBoolean(data[2])); setVariant(CatVariantUtil.valueOf(data[3]).getCatVariant()); - setCollarColor(DyeColor.valueOf(data[4])); + if (Boolean.parseBoolean(data[4])) { + setTame(true); + setCollarColor(DyeColor.valueOf(data[5])); + } setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); moveControl = new ControllerWASD(this, player.getUniqueId(), 0.4F); targetSelector.getAvailableGoals().clear(); diff --git a/src/main/java/lee/code/pets/utils/PetDataUtil.java b/src/main/java/lee/code/pets/utils/PetDataUtil.java index b075a4d..0e48fd2 100644 --- a/src/main/java/lee/code/pets/utils/PetDataUtil.java +++ b/src/main/java/lee/code/pets/utils/PetDataUtil.java @@ -102,7 +102,8 @@ public static String getPetData(EntityType entityType, String[] data, Option opt case NAME -> {return data[1];} case BABY -> {return data[2];} case VARIANT -> {return data[3];} - case COLOR -> {return data[4];} + case COLLAR -> {return data[4];} + case COLOR -> {return data[5];} } } case WOLF -> { @@ -237,7 +238,8 @@ public static String serializePetData(Entity entity) { case CAT -> { final Cat.Type catType = entity instanceof Cat cat ? cat.getCatType() : Cat.Type.ALL_BLACK; final DyeColor color = entity instanceof Cat cat ? cat.getCollarColor() : DyeColor.RED; - return startingData + sep + isBaby + sep + catType.name() + sep + color.name(); + final boolean hasCollar = entity instanceof Cat cat && cat.isTamed(); + return startingData + sep + isBaby + sep + catType.name() + sep + hasCollar + sep + color.name(); } case RABBIT -> { final RabbitVariantUtil rabbitVariant = RabbitVariantUtil.getVariant(entity); @@ -374,10 +376,11 @@ public static String addNewPetData(EntityType entityType, String[] data, String } case CAT -> { switch (option) { - case NAME -> {return data[0] + sep + newData + sep + data[2] + sep + data[3] + sep + data[4];} - case BABY -> {return data[0] + sep + data[1] + sep + newData + sep + data[3] + sep + data[4];} - case VARIANT -> {return data[0] + sep + data[1] + sep + data[2] + sep + newData + sep + data[4];} - case COLOR -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + newData;} + case NAME -> {return data[0] + sep + newData + sep + data[2] + sep + data[3] + sep + data[4] + sep + data[5];} + case BABY -> {return data[0] + sep + data[1] + sep + newData + sep + data[3] + sep + data[4] + sep + data[5];} + case VARIANT -> {return data[0] + sep + data[1] + sep + data[2] + sep + newData + sep + data[4] + sep + data[5];} + case COLLAR -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + newData + sep + data[5];} + case COLOR -> {return data[0] + sep + data[1] + sep + data[2] + sep + data[3] + sep + data[4] + sep + newData;} } } case BEE -> {