diff --git a/modules/API/src/main/java/de/Keyle/MyPet/api/Configuration.java b/modules/API/src/main/java/de/Keyle/MyPet/api/Configuration.java index c018126f5..172b7b986 100644 --- a/modules/API/src/main/java/de/Keyle/MyPet/api/Configuration.java +++ b/modules/API/src/main/java/de/Keyle/MyPet/api/Configuration.java @@ -194,6 +194,9 @@ public static class Backpack { } public static class MyPet { + public static class Axolotl { + public static ConfigItem GROW_UP_ITEM; + } public static class Bat { @@ -203,12 +206,18 @@ public static class Bat { public static class Bee { public static boolean CAN_GLIDE = true; + public static ConfigItem GROW_UP_ITEM; } public static class Blaze { public static boolean CAN_GLIDE = true; } + + public static class Cat { + + public static ConfigItem GROW_UP_ITEM; + } public static class Chicken { @@ -227,7 +236,17 @@ public static class Donkey { public static ConfigItem GROW_UP_ITEM; } + + public static class Drowned { + + public static ConfigItem GROW_UP_ITEM; + } + + public static class Fox { + public static ConfigItem GROW_UP_ITEM; + } + public static class EnderDragon { public static boolean CAN_GLIDE = true; @@ -253,6 +272,11 @@ public static class Horse { public static ConfigItem GROW_UP_ITEM; } + + public static class Husk { + + public static ConfigItem GROW_UP_ITEM; + } public static class IronGolem { @@ -280,6 +304,11 @@ public static class Ocelot { public static ConfigItem GROW_UP_ITEM; } + public static class Panda { + + public static ConfigItem GROW_UP_ITEM; + } + public static class Parrot { public static boolean CAN_GLIDE = true; @@ -310,6 +339,11 @@ public static class PigZombie { public static ConfigItem GROW_UP_ITEM; } + public static class PolarBear { + + public static ConfigItem GROW_UP_ITEM; + } + public static class Rabbit { public static ConfigItem GROW_UP_ITEM; @@ -336,6 +370,16 @@ public static class Strider { public static ConfigItem GROW_UP_ITEM; } + + public static class TraderLlama { + + public static ConfigItem GROW_UP_ITEM; + } + + public static class Turtle { + + public static ConfigItem GROW_UP_ITEM; + } public static class Vex { diff --git a/modules/API/src/main/java/de/Keyle/MyPet/api/util/ReflectionUtil.java b/modules/API/src/main/java/de/Keyle/MyPet/api/util/ReflectionUtil.java index 8aed85c88..ed9ea4468 100644 --- a/modules/API/src/main/java/de/Keyle/MyPet/api/util/ReflectionUtil.java +++ b/modules/API/src/main/java/de/Keyle/MyPet/api/util/ReflectionUtil.java @@ -26,6 +26,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.bukkit.Bukkit; + public class ReflectionUtil { @SuppressWarnings("rawtypes") @@ -119,14 +121,17 @@ public static boolean setFinalFieldValue(String fieldName, Object target, Object public static boolean setFinalFieldValue(@NonNull Field field, Object target, Object value) { try { field.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - + + if(Integer.parseInt(System.getProperty("java.version").split("\\.")[0]) < 16) { //Java-Version-Check + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + } + field.set(target, value); return true; - } catch (Throwable ignored) { + } catch (Exception ignored) { + ignored.printStackTrace(); } return false; } diff --git a/modules/MyPet/pom.xml b/modules/MyPet/pom.xml index d2284fb3f..c5ea912b6 100644 --- a/modules/MyPet/pom.xml +++ b/modules/MyPet/pom.xml @@ -24,7 +24,7 @@ de.keyle mypet - 3.12-RC1 + 3.12-RC2 jar MyPet https://www.spigotmc.org/resources/mypet.12725/ diff --git a/modules/Plugin/src/main/java/de/Keyle/MyPet/util/ConfigurationLoader.java b/modules/Plugin/src/main/java/de/Keyle/MyPet/util/ConfigurationLoader.java index 1f1a19808..657d9c32f 100644 --- a/modules/Plugin/src/main/java/de/Keyle/MyPet/util/ConfigurationLoader.java +++ b/modules/Plugin/src/main/java/de/Keyle/MyPet/util/ConfigurationLoader.java @@ -20,9 +20,38 @@ package de.Keyle.MyPet.util; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.event.entity.CreatureSpawnEvent; + import com.google.common.collect.Lists; + import de.Keyle.MyPet.MyPetApi; -import de.Keyle.MyPet.api.Configuration.*; +import de.Keyle.MyPet.api.Configuration.Entity; +import de.Keyle.MyPet.api.Configuration.HungerSystem; +import de.Keyle.MyPet.api.Configuration.LevelSystem; +import de.Keyle.MyPet.api.Configuration.Log; +import de.Keyle.MyPet.api.Configuration.Misc; +import de.Keyle.MyPet.api.Configuration.MyPet; +import de.Keyle.MyPet.api.Configuration.Name; +import de.Keyle.MyPet.api.Configuration.Permissions; +import de.Keyle.MyPet.api.Configuration.Repository; +import de.Keyle.MyPet.api.Configuration.Respawn; +import de.Keyle.MyPet.api.Configuration.Skilltree; +import de.Keyle.MyPet.api.Configuration.Update; import de.Keyle.MyPet.api.entity.DefaultInfo; import de.Keyle.MyPet.api.entity.MyPetType; import de.Keyle.MyPet.api.skill.experience.MonsterExperience; @@ -31,18 +60,6 @@ import de.Keyle.MyPet.api.util.NameFilter; import de.Keyle.MyPet.api.util.configuration.settings.Settings; import de.Keyle.MyPet.util.sentry.SentryErrorReporter; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.EntityType; -import org.bukkit.event.entity.CreatureSpawnEvent; - -import java.io.File; -import java.io.IOException; -import java.util.*; public class ConfigurationLoader { @@ -521,29 +538,39 @@ public static void loadCompatConfiguration() { MyPetApi.getLogger().warning("There was an error while loading pet-config.yml"); } } - + MyPet.Axolotl.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Axolotl.GrowUpItem", "experience_bottle")); + MyPet.Bee.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Bee.GrowUpItem", "experience_bottle")); + MyPet.Cat.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Cat.GrowUpItem", "experience_bottle")); MyPet.Chicken.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Chicken.GrowUpItem", "experience_bottle")); MyPet.Cow.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Cow.GrowUpItem", "experience_bottle")); + MyPet.Donkey.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Donkey.GrowUpItem", "experience_bottle")); + MyPet.Drowned.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Drowned.GrowUpItem", "experience_bottle")); + MyPet.Fox.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Fox.GrowUpItem", "experience_bottle")); + MyPet.Goat.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Goat.GrowUpItem", "experience_bottle")); + MyPet.Hoglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Hoglin.GrowUpItem", "experience_bottle")); MyPet.Horse.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Horse.GrowUpItem", "" + "bread")); + MyPet.Husk.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Husk.GrowUpItem", "experience_bottle")); MyPet.Llama.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Llama.GrowUpItem", "experience_bottle")); MyPet.Mooshroom.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Mooshroom.GrowUpItem", "experience_bottle")); + MyPet.Mule.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Mule.GrowUpItem", "experience_bottle")); MyPet.Ocelot.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Ocelot.GrowUpItem", "experience_bottle")); + MyPet.Panda.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Panda.GrowUpItem", "experience_bottle")); MyPet.Pig.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Pig.GrowUpItem", "experience_bottle")); + MyPet.Piglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Piglin.GrowUpItem", "experience_bottle")); + MyPet.PiglinBrute.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PiglinBrute.GrowUpItem", "experience_bottle")); + MyPet.PigZombie.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PigZombie.GrowUpItem", "experience_bottle")); + MyPet.PolarBear.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PolarBear.GrowUpItem", "experience_bottle")); + MyPet.Rabbit.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Rabbit.GrowUpItem", "experience_bottle")); MyPet.Sheep.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Sheep.GrowUpItem", "experience_bottle")); + MyPet.SkeletonHorse.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.SkeletonHorse.GrowUpItem", "experience_bottle")); + MyPet.Strider.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Strider.GrowUpItem", "experience_bottle")); + MyPet.TraderLlama.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.TraderLlama.GrowUpItem", "experience_bottle")); + MyPet.Turtle.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Turtle.GrowUpItem", "experience_bottle")); MyPet.Villager.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Villager.GrowUpItem", "experience_bottle")); MyPet.Wolf.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Wolf.GrowUpItem", "experience_bottle")); + MyPet.Zoglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Zoglin.GrowUpItem", "experience_bottle")); MyPet.Zombie.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Zombie.GrowUpItem", "experience_bottle")); - MyPet.PigZombie.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PigZombie.GrowUpItem", "experience_bottle")); - MyPet.Rabbit.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Rabbit.GrowUpItem", "experience_bottle")); MyPet.ZombieHorse.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.ZombieHorse.GrowUpItem", "experience_bottle")); - MyPet.SkeletonHorse.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.SkeletonHorse.GrowUpItem", "experience_bottle")); - MyPet.Mule.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Mule.GrowUpItem", "experience_bottle")); - MyPet.Donkey.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Donkey.GrowUpItem", "experience_bottle")); - MyPet.Zoglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Zoglin.GrowUpItem", "experience_bottle")); - MyPet.Hoglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Hoglin.GrowUpItem", "experience_bottle")); - MyPet.Strider.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Strider.GrowUpItem", "experience_bottle")); - MyPet.Piglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.Piglin.GrowUpItem", "experience_bottle")); - MyPet.PiglinBrute.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.PiglinBrute.GrowUpItem", "experience_bottle")); MyPet.ZombifiedPiglin.GROW_UP_ITEM = ConfigItem.createConfigItem(config.getString("MyPet.Pets.ZombifiedPiglin.GrowUpItem", "experience_bottle")); for (MyPetType petType : MyPetType.values()) { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java index 9d04d7fee..fb21d39c7 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/EntityMyPet.java @@ -183,7 +183,6 @@ public EntityMyPet(Level world, MyPet myPet) { } protected void replaceCraftAttributes() { - //TODO check this Field craftAttributesField = ReflectionUtil.getField(LivingEntity.class, "craftAttributes"); CraftAttributeMap craftAttributes = new CraftAttributeMap(this.getAttributes()); ReflectionUtil.setFinalFieldValue(craftAttributesField, this, craftAttributes); diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java index ed39ea64b..062706edf 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/MyAttributeDefaults.java @@ -22,10 +22,9 @@ import java.util.HashMap; -import org.bukkit.Bukkit; - import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.GlowSquid; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ambient.Bat; import net.minecraft.world.entity.animal.Bee; @@ -103,7 +102,7 @@ public class MyAttributeDefaults { - private static final FastMap, AttributeSupplier> defaultAttribute = new FastMap<>(); + private static final FastMap, AttributeSupplier> defaultAttribute = new FastMap<>(); static { defaultAttribute @@ -189,14 +188,14 @@ public static AttributeSupplier getAttribute(EntityType types) { return defaultAttribute.get(types); } - public static void registerCustomEntityType(EntityType customType, EntityType rootType) { + public static void registerCustomEntityType(EntityType customType, EntityType rootType) { defaultAttribute.put(customType, getAttribute(rootType)); } static class FastMap extends HashMap { - public FastMap putFast(K key, AttributeSupplier attributeSupplier) { - put(key, (V) attributeSupplier); + public FastMap putFast(K key, V value) { + put(key, value); return this; } } diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java index 0c51473e3..17fcbbe34 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyAxolotl.java @@ -22,6 +22,7 @@ import org.bukkit.block.data.Ageable; +import de.Keyle.MyPet.api.Configuration; import de.Keyle.MyPet.api.entity.EntitySize; import de.Keyle.MyPet.api.entity.MyPet; import de.Keyle.MyPet.api.entity.types.MyAxolotl; @@ -29,7 +30,11 @@ import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @EntitySize(width = 0.7F, height = 1.3F) @@ -56,6 +61,27 @@ protected String getHurtSound() { protected String getLivingSound() { return "entity.axolotl.idle_air"; } + + @Override + public InteractionResult handlePlayerInteraction(final Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; + } + + if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { + if (Configuration.MyPet.Hoglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); + if (itemStack.getCount() <= 0) { + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); + } + } + getMyPet().setBaby(false); + return InteractionResult.CONSUME; + } + } + return InteractionResult.PASS; + } @Override protected void defineSynchedData() { diff --git a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java index e2c712ba9..4da5c859d 100644 --- a/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java +++ b/modules/v1_17_R1/src/main/java/de/Keyle/MyPet/compat/v1_17_R1/entity/types/EntityMyBee.java @@ -32,6 +32,10 @@ import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @EntitySize(width = 0.6F, height = 0.6f) @@ -118,6 +122,27 @@ public void onLivingUpdate() { } } } + + @Override + public InteractionResult handlePlayerInteraction(final Player entityhuman, InteractionHand enumhand, final ItemStack itemStack) { + if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) { + return InteractionResult.CONSUME; + } + + if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { + if (Configuration.MyPet.Hoglin.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) { + if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) { + itemStack.shrink(1); + if (itemStack.getCount() <= 0) { + entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY); + } + } + getMyPet().setBaby(false); + return InteractionResult.CONSUME; + } + } + return InteractionResult.PASS; + } @Override protected void doMyPetTick() {