diff --git a/build.gradle.kts b/build.gradle.kts index 638d91d..fb18f1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,9 +33,13 @@ dependencies { //protocol-lib compileOnly ("com.comphenix.protocol:ProtocolLib:5.1.0") + + //goldman player data + compileOnly ("lee.code.playerdata:playerdata:1.0.0") } repositories { + mavenLocal() mavenCentral() // You can add more repositories if needed maven { name = "protocollib" diff --git a/src/main/java/lee/code/pets/database/DatabaseManager.java b/src/main/java/lee/code/pets/database/DatabaseManager.java index 437d460..7d80bef 100644 --- a/src/main/java/lee/code/pets/database/DatabaseManager.java +++ b/src/main/java/lee/code/pets/database/DatabaseManager.java @@ -54,12 +54,29 @@ public void closeConnection() { } } + private void alterDatabase() { + try { + //effects + petsDao.executeRaw("ALTER TABLE pets ADD COLUMN effect BOOLEAN DEFAULT 1;"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + private void updateDatabase() { try { - final QueryBuilder queryBuilder = petsDao.queryBuilder(); - queryBuilder.where().like("data", "%WITHER,%"); + //blaze + final QueryBuilder blazeBuilder = petsDao.queryBuilder(); + blazeBuilder.where().like("data", "%BLAZE,%"); + for (PetTable petTable : blazeBuilder.query()) { + petTable.setData(petTable.getData() + ",false"); + petsDao.update(petTable); + } - for (PetTable petTable : queryBuilder.query()) { + //vex + final QueryBuilder vexBuilder = petsDao.queryBuilder(); + vexBuilder.where().like("data", "%VEX,%"); + for (PetTable petTable : vexBuilder.query()) { petTable.setData(petTable.getData() + ",false"); petsDao.update(petTable); } diff --git a/src/main/java/lee/code/pets/database/cache/CachePets.java b/src/main/java/lee/code/pets/database/cache/CachePets.java index 84a8ad5..f4eae8e 100644 --- a/src/main/java/lee/code/pets/database/cache/CachePets.java +++ b/src/main/java/lee/code/pets/database/cache/CachePets.java @@ -61,4 +61,14 @@ public void deletePet(int id) { playerPetData.removePlayerPet(petTable.getOwner(), id); petsCache.remove(id); } + + public void setPetEffect(int id, boolean result) { + final PetTable petTable = getPetTable(id); + petTable.setEffect(result); + updatePetDatabase(petTable); + } + + public boolean getPetEffect(int id) { + return getPetTable(id).isEffect(); + } } diff --git a/src/main/java/lee/code/pets/database/tables/PetTable.java b/src/main/java/lee/code/pets/database/tables/PetTable.java index 4ecced7..68bbd09 100644 --- a/src/main/java/lee/code/pets/database/tables/PetTable.java +++ b/src/main/java/lee/code/pets/database/tables/PetTable.java @@ -22,9 +22,13 @@ public class PetTable { @DatabaseField(columnName = "data", canBeNull = false) private String data; + @DatabaseField(columnName = "effect", canBeNull = false) + private boolean effect; + public PetTable(int id, UUID owner, String data) { this.id = id; this.owner = owner; this.data = data; + this.effect = true; } } diff --git a/src/main/java/lee/code/pets/lang/Lang.java b/src/main/java/lee/code/pets/lang/Lang.java index f66c128..a2d9e35 100644 --- a/src/main/java/lee/code/pets/lang/Lang.java +++ b/src/main/java/lee/code/pets/lang/Lang.java @@ -25,6 +25,7 @@ public enum Lang { MENU_RENAME_SUCCESSFUL("&aYou successfully renamed your pet to &f{0}&a!"), MENU_RENAME_MESSAGE("&aPlease type your new pet's name in chat&7:"), MENU_PET_ITEM_NAME("&e&lPet Name&7:"), + MENU_PET_EFFECT_LORE("&3&lEffect&7: &e{0}\n&3&lAmplifier&7: &e{1}\n&3&lEnabled&7: &e{2}"), MENU_PET_ITEM_LORE("&f{0}\n \n&e&lActions&7:\n&e» &7Right-Click &eEdit Pet\n&e» &7Left-Click &eSpawn Pet\n&e» &7Sneak-Click &eDelete Pet"), CAPTURE_SUCCESSFUL("&aYou successfully captured a &3{0}&a!"), ERROR_RENAME_COMMAND("&cYou can't use commands until you type in a new pet name."), diff --git a/src/main/java/lee/code/pets/menus/menu/PetOptionMenu.java b/src/main/java/lee/code/pets/menus/menu/PetOptionMenu.java index e677bca..0f4babf 100644 --- a/src/main/java/lee/code/pets/menus/menu/PetOptionMenu.java +++ b/src/main/java/lee/code/pets/menus/menu/PetOptionMenu.java @@ -87,7 +87,7 @@ private MenuButton createOptionButton(Player player, Option option) { final String marking = PetDataUtil.getNextHorseMarking(targetData); cachePets.updatePetData(petID, PetDataUtil.addNewPetData(entityType, petData, marking, option)); } - case BABY, SADDLE, CHEST, HORNS, ANGRY, STUNG, NECTAR, PUMPKIN, COLLAR, POWERED, DYE -> { + case BABY, SADDLE, CHEST, HORNS, ANGRY, STUNG, NECTAR, PUMPKIN, COLLAR, POWERED, DYE, CHARGED -> { final String petOption = String.valueOf(!Boolean.parseBoolean(targetData)); cachePets.updatePetData(petID, PetDataUtil.addNewPetData(entityType, petData, petOption, option)); } @@ -118,14 +118,25 @@ private MenuButton createOptionButton(Player player, Option option) { } private void addInterfaceButtons(Player player) { - addButton(30, new MenuButton() + addButton(29, new MenuButton() + .creator(p -> MenuItem.PET_EFFECT.createPetEffectItem(entityType, pets.getCacheManager().getCachePets().getPetEffect(petID))) + .consumer(e -> { + final CachePets cachePets = pets.getCacheManager().getCachePets(); + getMenuSoundManager().playClickSound(player); + cachePets.setPetEffect(petID, !cachePets.getPetEffect(petID)); + pets.getPetManager().removeActivePet(player); + clearButtons(); + decorate(player); + })); + addButton(31, new MenuButton() .creator(p -> MenuItem.BACK_MENU.createItem()) .consumer(e -> { getMenuSoundManager().playClickSound(player); pets.getMenuManager().openMenu(new PetMenu(pets), player); })); - addButton(32, new MenuButton() - .creator(p -> MenuItem.SPAWN_PET.createSpawnPetItem(entityType)).consumer(e -> { + addButton(33, new MenuButton() + .creator(p -> MenuItem.SPAWN_PET.createSpawnPetItem(entityType)) + .consumer(e -> { final CachePets cachePets = pets.getCacheManager().getCachePets(); getMenuSoundManager().playClickSound(player); pets.getPetManager().removeActivePet(player); diff --git a/src/main/java/lee/code/pets/menus/menu/menudata/MenuItem.java b/src/main/java/lee/code/pets/menus/menu/menudata/MenuItem.java index 96c63f3..670bd6c 100644 --- a/src/main/java/lee/code/pets/menus/menu/menudata/MenuItem.java +++ b/src/main/java/lee/code/pets/menus/menu/menudata/MenuItem.java @@ -1,13 +1,16 @@ package lee.code.pets.menus.menu.menudata; +import lee.code.pets.lang.Lang; import lee.code.pets.utils.CoreUtil; import lee.code.pets.utils.ItemUtil; +import lee.code.pets.utils.PetEffects; import lombok.AllArgsConstructor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; @AllArgsConstructor public enum MenuItem { @@ -19,6 +22,7 @@ public enum MenuItem { CONFIRM(Material.LIME_STAINED_GLASS_PANE, "&2&lConfirm Delete", null, false, false, null), CANCEL(Material.RED_STAINED_GLASS_PANE, "&c&lCancel Delete", null, false, false, null), DEACTIVATE_PET(Material.BARRIER, "&c&lDeactivate Pet", null, false, false, null), + PET_EFFECT(Material.POTION, "&d&lPassive Effect", null, true, true, null), ; private final Material material; @@ -42,4 +46,17 @@ public ItemStack createSpawnPetItem(EntityType entityType) { head.setItemMeta(itemMeta); return head; } + + public ItemStack createPetEffectItem(EntityType entityType, boolean effect) { + final ItemStack item = ItemUtil.createItem(material, name, createPetEffectLore(entityType, effect), 0, skin); + if (hideItemFlags) ItemUtil.hideItemFlags(item); + if (enchantItem) ItemUtil.enchantItem(item, Enchantment.ARROW_INFINITE, 1); + return item; + } + + private String createPetEffectLore(EntityType entityType, boolean effect) { + final String effectColor = effect ? "&2" : "&c"; + final PotionEffect potionEffect = PetEffects.valueOf(entityType.name()).getPotionEffect(); + return Lang.MENU_PET_EFFECT_LORE.getString(new String[]{CoreUtil.capitalize(potionEffect.getType().getName()), String.valueOf(potionEffect.getAmplifier()), effectColor + CoreUtil.capitalize(String.valueOf(effect))}); + } } diff --git a/src/main/java/lee/code/pets/menus/menu/menudata/options/Option.java b/src/main/java/lee/code/pets/menus/menu/menudata/options/Option.java index 0e706ad..78cb08d 100644 --- a/src/main/java/lee/code/pets/menus/menu/menudata/options/Option.java +++ b/src/main/java/lee/code/pets/menus/menu/menudata/options/Option.java @@ -29,6 +29,7 @@ public enum Option { LEVEL(Material.EXPERIENCE_BOTTLE, "&e&lLevel"), COLLAR(Material.LEAD, "&e&lCollar"), POWERED(Material.TNT, "&e&lPowered"), + CHARGED(Material.MAGMA_BLOCK, "&e&lCharged"), SIZE(Material.BONE_MEAL, "&e&lSize"), DYE(Material.FIREWORK_STAR, "&e&lDye") 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 6bdb9c0..73d1e82 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 @@ -50,7 +50,7 @@ public enum OptionSelector { TADPOLE(new String[] {Option.NAME.name()}), TROPICAL_FISH(new String[] {Option.NAME.name(), Option.VARIANT.name(), Option.BODY_COLOR.name(), Option.PATTERN_COLOR.name()}), TURTLE(new String[] {Option.NAME.name(), Option.BABY.name()}), - BLAZE(new String[] {Option.NAME.name()}), + BLAZE(new String[] {Option.NAME.name(), Option.CHARGED.name()}), CAVE_SPIDER(new String[] {Option.NAME.name()}), CREEPER(new String[] {Option.NAME.name(), Option.POWERED.name()}), DROWNED(new String[] {Option.NAME.name(), Option.BABY.name()}), @@ -71,7 +71,7 @@ public enum OptionSelector { SKELETON(new String[] {Option.NAME.name()}), SPIDER(new String[] {Option.NAME.name()}), STRAY(new String[] {Option.NAME.name()}), - VEX(new String[] {Option.NAME.name()}), + VEX(new String[] {Option.NAME.name(), Option.ANGRY.name()}), VINDICATOR(new String[] {Option.NAME.name()}), WARDEN(new String[] {Option.NAME.name()}), WITCH(new String[] {Option.NAME.name()}), diff --git a/src/main/java/lee/code/pets/pets/PetManager.java b/src/main/java/lee/code/pets/pets/PetManager.java index 124167b..c40ca45 100644 --- a/src/main/java/lee/code/pets/pets/PetManager.java +++ b/src/main/java/lee/code/pets/pets/PetManager.java @@ -1,5 +1,6 @@ package lee.code.pets.pets; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import lee.code.pets.Pets; import lee.code.pets.database.cache.CachePets; import lee.code.pets.pets.pet.animal.*; @@ -8,8 +9,12 @@ import lee.code.pets.pets.pet.monster.*; import lee.code.pets.utils.CoreUtil; import lee.code.pets.utils.PetDataUtil; +import lee.code.pets.utils.PetEffects; +import lee.code.playerdata.PlayerDataAPI; import net.minecraft.world.entity.Entity; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.OfflinePlayer; import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -17,11 +22,13 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; public class PetManager { private final Pets pets; private final ConcurrentHashMap petTracker = new ConcurrentHashMap<>(); private final ConcurrentHashMap activePetTracker = new ConcurrentHashMap<>(); + private final ConcurrentHashMap petEffectTasks = new ConcurrentHashMap<>(); public PetManager(Pets pets) { this.pets = pets; @@ -112,6 +119,7 @@ private void spawn(Player player, Location location, int id, Entity entity) { final CraftEntity craftEntity = entity.getBukkitEntity(); addToPetTracker(id, craftEntity.getUniqueId(), player.getUniqueId()); craftEntity.spawnAt(location, CreatureSpawnEvent.SpawnReason.CUSTOM); + startEffectTimer(player.getUniqueId(), craftEntity.getType(), id); } private void addToPetTracker(int id, UUID entity, UUID player) { @@ -157,6 +165,7 @@ public void removePet(Player player) { final org.bukkit.entity.Entity entity = player.getWorld().getEntity(getActivePetUUID(activePet)); if (entity != null) entity.remove(); removeFromPetTracker(activePet, player.getUniqueId()); + stopEffectTimer(player.getUniqueId()); } public void capturePet(Player player, org.bukkit.entity.Entity entity) { @@ -178,4 +187,24 @@ public boolean canCaptureNewPet(Player player) { final int count = pets.getCacheManager().getCachePets().getPlayerPetData().getPetCount(player.getUniqueId()); return count + 1 <= getMaxPets(player); } + + private void startEffectTimer(UUID uuid, EntityType entityType, int petID) { + stopEffectTimer(uuid); + if (!pets.getCacheManager().getCachePets().getPetEffect(petID)) return; + petEffectTasks.put(uuid, Bukkit.getAsyncScheduler().runAtFixedRate(pets, scheduledTask -> { + final Player player = PlayerDataAPI.getOnlinePlayer(uuid); + if (player == null) { + stopEffectTimer(uuid); + return; + } + player.getScheduler().run(pets, task -> player.addPotionEffect(PetEffects.valueOf(entityType.name()).getPotionEffect()), null); + }, 0, 3, TimeUnit.SECONDS)); + } + + public void stopEffectTimer(UUID uuid) { + if (petEffectTasks.containsKey(uuid)) { + petEffectTasks.get(uuid).cancel(); + petEffectTasks.remove(uuid); + } + } } diff --git a/src/main/java/lee/code/pets/pets/pet/monster/BlazePet.java b/src/main/java/lee/code/pets/pets/pet/monster/BlazePet.java index ee8544b..b47f812 100644 --- a/src/main/java/lee/code/pets/pets/pet/monster/BlazePet.java +++ b/src/main/java/lee/code/pets/pets/pet/monster/BlazePet.java @@ -5,14 +5,20 @@ import lee.code.pets.utils.CoreUtil; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.monster.Blaze; +import net.minecraft.world.entity.monster.Monster; import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityTargetEvent; -public class BlazePet extends Blaze { +public class BlazePet extends Monster { + private static final EntityDataAccessor DATA_FLAGS_ID = SynchedEntityData.defineId(BlazePet.class, EntityDataSerializers.BYTE); public BlazePet(Player player, String[] data) { super(EntityType.BLAZE, ((CraftWorld) player.getLocation().getWorld()).getHandle()); @@ -23,6 +29,7 @@ public BlazePet(Player player, String[] data) { setCanPickUpLoot(false); setNoGravity(true); setMaxUpStep(1.0F); + setCharged(Boolean.parseBoolean(data[2])); collides = false; setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(data[1]))); setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); @@ -31,6 +38,11 @@ public BlazePet(Player player, String[] data) { getBrain().removeAllBehaviors(); } + @Override + protected SoundEvent getAmbientSound() { + return SoundEvents.BLAZE_AMBIENT; + } + @Override protected void registerGoals() { goalSelector.addGoal(0, new FollowOwnerFlyingGoal(this, 0.4, 5, 10)); @@ -44,4 +56,17 @@ public void load(CompoundTag compoundTag) { public boolean save(CompoundTag compoundTag) { return false; } + + @Override + protected void defineSynchedData() { + super.defineSynchedData(); + this.entityData.define(DATA_FLAGS_ID, (byte) 0); + } + + private void setCharged(boolean fireActive) { + byte b = entityData.get(DATA_FLAGS_ID); + if (fireActive) b = (byte)(b | 1); + else b = (byte)(b & -2); + entityData.set(DATA_FLAGS_ID, b); + } } diff --git a/src/main/java/lee/code/pets/pets/pet/monster/VexPet.java b/src/main/java/lee/code/pets/pets/pet/monster/VexPet.java index 3892b45..a4797c9 100644 --- a/src/main/java/lee/code/pets/pets/pet/monster/VexPet.java +++ b/src/main/java/lee/code/pets/pets/pet/monster/VexPet.java @@ -5,6 +5,9 @@ import lee.code.pets.utils.CoreUtil; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.entity.EntityType; @@ -15,6 +18,7 @@ import org.bukkit.event.entity.EntityTargetEvent; public class VexPet extends Mob { + protected static final EntityDataAccessor DATA_FLAGS_ID = SynchedEntityData.defineId(VexPet.class, EntityDataSerializers.BYTE); public VexPet(Player player, String[] data) { super(EntityType.VEX, ((CraftWorld) player.getLocation().getWorld()).getHandle()); @@ -26,6 +30,7 @@ public VexPet(Player player, String[] data) { setNoGravity(true); setMaxUpStep(1.0F); collides = false; + setIsCharging(Boolean.parseBoolean(data[2])); setCustomName(Component.Serializer.fromJson(CoreUtil.serializeColorComponentJson(data[1]))); setTarget(((CraftPlayer) player).getHandle(), EntityTargetEvent.TargetReason.CUSTOM, false); moveControl = new ControllerWASDFlying(this, player.getUniqueId(), 0.3F); @@ -51,4 +56,22 @@ public void load(CompoundTag compoundTag) { public boolean save(CompoundTag compoundTag) { return false; } + + @Override + protected void defineSynchedData() { + super.defineSynchedData(); + this.entityData.define(DATA_FLAGS_ID, (byte) 0); + } + + private void setVexFlag(int mask, boolean value) { + final byte b0 = entityData.get(DATA_FLAGS_ID); + final int j; + if (value) j = b0 | mask; + else j = b0 & ~mask; + entityData.set(DATA_FLAGS_ID, (byte) (j & 255)); + } + + public void setIsCharging(boolean charging) { + setVexFlag(1, charging); + } } diff --git a/src/main/java/lee/code/pets/utils/PetDataUtil.java b/src/main/java/lee/code/pets/utils/PetDataUtil.java index 24eae29..b29d672 100644 --- a/src/main/java/lee/code/pets/utils/PetDataUtil.java +++ b/src/main/java/lee/code/pets/utils/PetDataUtil.java @@ -13,7 +13,7 @@ public class PetDataUtil { public static String getPetData(EntityType entityType, String[] data, Option option) { switch (entityType) { - case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, BLAZE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VEX, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { + case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { return data[1]; } case COW, CHICKEN, HOGLIN, OCELOT, PIG, POLAR_BEAR, SNIFFER, ZOGLIN, TURTLE, DROWNED, HUSK, PIGLIN, ZOMBIE, ZOMBIFIED_PIGLIN -> { @@ -22,6 +22,18 @@ public static String getPetData(EntityType entityType, String[] data, Option opt case BABY -> {return data[2];} } } + case BLAZE -> { + switch (option) { + case NAME -> {return data[1];} + case CHARGED -> {return data[2];} + } + } + case VEX -> { + switch (option) { + case NAME -> {return data[1];} + case ANGRY -> {return data[2];} + } + } case MAGMA_CUBE, SLIME -> { switch (option) { case NAME -> {return data[1];} @@ -171,7 +183,7 @@ public static String serializePetData(Entity entity) { final String sep = ","; final String startingData = entityType.name() + sep + petName; switch (entityType) { - case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, BLAZE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VEX, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { + case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { return startingData; } case COW, CHICKEN, HOGLIN, OCELOT, PIG, POLAR_BEAR, SNIFFER, ZOGLIN, TURTLE, DROWNED, HUSK, PIGLIN, ZOMBIE, ZOMBIFIED_PIGLIN -> { @@ -280,7 +292,7 @@ public static String serializePetData(Entity entity) { final boolean charged = entity instanceof Creeper creeper && creeper.isPowered(); return startingData + sep + charged; } - case WITHER -> { + case WITHER, VEX, BLAZE -> { return startingData + sep + "false"; } case VILLAGER, ZOMBIE_VILLAGER -> { @@ -311,7 +323,7 @@ public static String serializePetData(Entity entity) { public static String addNewPetData(EntityType entityType, String[] data, String newData, Option option) { final String sep = ","; switch (entityType) { - case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, BLAZE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VEX, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { + case ALLAY, BAT, IRON_GOLEM, WANDERING_TRADER, COD, DOLPHIN, ELDER_GUARDIAN, GLOW_SQUID, GUARDIAN, PUFFERFISH, SALMON, SQUID, TADPOLE, CAVE_SPIDER, ENDERMAN, EVOKER, GHAST, ILLUSIONER, PHANTOM, PIGLIN_BRUTE, PILLAGER, RAVAGER, SILVERFISH, SKELETON, SPIDER, STRAY, VINDICATOR, WARDEN, WITCH, WITHER_SKELETON -> { return data[0] + sep + newData; } case COW, CHICKEN, HOGLIN, OCELOT, PIG, POLAR_BEAR, SNIFFER, ZOGLIN, TURTLE, DROWNED, HUSK, PIGLIN, ZOMBIE, ZOMBIFIED_PIGLIN -> { @@ -333,6 +345,18 @@ public static String addNewPetData(EntityType entityType, String[] data, String case SIZE -> {return data[0] + sep + data[1] + sep + newData;} } } + case BLAZE -> { + switch (option) { + case NAME -> {return data[0] + sep + newData + sep + data[2];} + case CHARGED -> {return data[0] + sep + data[1] + sep + newData;} + } + } + case VEX -> { + switch (option) { + case NAME -> {return data[0] + sep + newData + sep + data[2];} + case ANGRY -> {return data[0] + sep + data[1] + sep + newData;} + } + } case SHULKER -> { switch (option) { case NAME -> {return data[0] + sep + newData + sep + data[2] + sep + data[3];} diff --git a/src/main/java/lee/code/pets/utils/PetEffects.java b/src/main/java/lee/code/pets/utils/PetEffects.java new file mode 100644 index 0000000..55fcc78 --- /dev/null +++ b/src/main/java/lee/code/pets/utils/PetEffects.java @@ -0,0 +1,95 @@ +package lee.code.pets.utils; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.entity.EntityType; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +@AllArgsConstructor +public enum PetEffects { + COW(EntityType.COW, new PotionEffect(PotionEffectType.LUCK, 20 * 10, 0)), + SHEEP(EntityType.SHEEP, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + ALLAY(EntityType.ALLAY, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 1)), + AXOLOTL(EntityType.AXOLOTL, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 0)), + BAT(EntityType.BAT, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + CAT(EntityType.CAT, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 0)), + CAMEL(EntityType.CAMEL, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 10, 0)), + CHICKEN(EntityType.CHICKEN, new PotionEffect(PotionEffectType.SLOW_FALLING, 20 * 10, 0)), + COD(EntityType.COD, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + DONKEY(EntityType.DONKEY, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + FOX(EntityType.FOX, new PotionEffect(PotionEffectType.JUMP, 20 * 10, 0)), + FROG(EntityType.FROG, new PotionEffect(PotionEffectType.JUMP, 20 * 10, 0)), + GLOW_SQUID(EntityType.GLOW_SQUID, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + HORSE(EntityType.HORSE, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 1)), + MUSHROOM_COW(EntityType.MUSHROOM_COW, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 1)), + MULE(EntityType.MULE, new PotionEffect(PotionEffectType.JUMP, 20 * 10, 0)), + OCELOT(EntityType.OCELOT, new PotionEffect(PotionEffectType.SLOW_FALLING, 20 * 10, 0)), + PARROT(EntityType.PARROT, new PotionEffect(PotionEffectType.HEALTH_BOOST, 20 * 10, 1)), + PIG(EntityType.PIG, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 0)), + PUFFERFISH(EntityType.PUFFERFISH, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + RABBIT(EntityType.RABBIT, new PotionEffect(PotionEffectType.JUMP, 20 * 10, 1)), + SALMON(EntityType.SALMON, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 1)), + SNIFFER(EntityType.SNIFFER, new PotionEffect(PotionEffectType.FAST_DIGGING, 20 * 10, 1)), + SNOWMAN(EntityType.SNOWMAN, new PotionEffect(PotionEffectType.SLOW_FALLING, 20 * 10, 0)), + SQUID(EntityType.SQUID, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + STRIDER(EntityType.STRIDER, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 10, 0)), + TADPOLE(EntityType.TADPOLE, new PotionEffect(PotionEffectType.LUCK, 20 * 10, 0)), + TROPICAL_FISH(EntityType.TROPICAL_FISH, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + TURTLE(EntityType.TURTLE, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + VILLAGER(EntityType.VILLAGER, new PotionEffect(PotionEffectType.HEAL, 20 * 10, 1)), + WANDERING_TRADER(EntityType.WANDERING_TRADER, new PotionEffect(PotionEffectType.INVISIBILITY, 20 * 10, 0)), + CAVE_SPIDER(EntityType.CAVE_SPIDER, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + DOLPHIN(EntityType.DOLPHIN, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + ENDERMAN(EntityType.ENDERMAN, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + GOAT(EntityType.GOAT, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + IRON_GOLEM(EntityType.IRON_GOLEM, new PotionEffect(PotionEffectType.HEALTH_BOOST, 20 * 10, 1)), + LLAMA(EntityType.LLAMA, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 0)), + PANDA(EntityType.PANDA, new PotionEffect(PotionEffectType.HEAL, 20 * 10, 0)), + PIGLIN(EntityType.PIGLIN, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + PIGLIN_BRUTE(EntityType.PIGLIN_BRUTE, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + ZOMBIFIED_PIGLIN(EntityType.ZOMBIFIED_PIGLIN, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + POLAR_BEAR(EntityType.POLAR_BEAR, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 0)), + SKELETON_HORSE(EntityType.SKELETON_HORSE, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 0)), + SPIDER(EntityType.SPIDER, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 10, 1)), + TRADER_LLAMA(EntityType.TRADER_LLAMA, new PotionEffect(PotionEffectType.LUCK, 20 * 10, 0)), + WOLF(EntityType.WOLF, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + CREEPER(EntityType.CREEPER, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 1)), + DROWNED(EntityType.DROWNED, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + ELDER_GUARDIAN(EntityType.ELDER_GUARDIAN, new PotionEffect(PotionEffectType.CONDUIT_POWER, 20 * 10, 1)), + ENDERMITE(EntityType.ENDERMITE, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 0)), + ILLUSIONER(EntityType.ILLUSIONER, new PotionEffect(PotionEffectType.INVISIBILITY, 20 * 10, 0)), + WITHER(EntityType.WITHER, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 1)), + BLAZE(EntityType.BLAZE, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 10, 1)), + EVOKER(EntityType.EVOKER, new PotionEffect(PotionEffectType.HEAL, 20 * 10, 1)), + GHAST(EntityType.GHAST, new PotionEffect(PotionEffectType.SLOW_FALLING, 20 * 10, 0)), + GUARDIAN(EntityType.GUARDIAN, new PotionEffect(PotionEffectType.WATER_BREATHING, 20 * 10, 0)), + HOGLIN(EntityType.HOGLIN, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 10, 1)), + ZOGLIN(EntityType.ZOGLIN, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 1)), + HUSK(EntityType.HUSK, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 1)), + MAGMA_CUBE(EntityType.MAGMA_CUBE, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 10, 1)), + PHANTOM(EntityType.PHANTOM, new PotionEffect(PotionEffectType.SLOW_FALLING, 20 * 10, 0)), + PILLAGER(EntityType.PILLAGER, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 1)), + RAVAGER(EntityType.RAVAGER, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 2)), + SHULKER(EntityType.SHULKER, new PotionEffect(PotionEffectType.LEVITATION, 20 * 10, 1)), + SILVERFISH(EntityType.SILVERFISH, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 0)), + SKELETON(EntityType.SKELETON, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 0)), + SLIME(EntityType.SLIME, new PotionEffect(PotionEffectType.JUMP, 20 * 10, 1)), + STRAY(EntityType.STRAY, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 1)), + VEX(EntityType.VEX, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 1)), + VINDICATOR(EntityType.VINDICATOR, new PotionEffect(PotionEffectType.NIGHT_VISION, 20 * 10, 0)), + WARDEN(EntityType.WARDEN, new PotionEffect(PotionEffectType.HEALTH_BOOST, 20 * 10, 2)), + WITCH(EntityType.WITCH, new PotionEffect(PotionEffectType.LUCK, 20 * 10, 1)), + WITHER_SKELETON(EntityType.WITHER_SKELETON, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 1)), + ZOMBIE(EntityType.ZOMBIE, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 10, 0)), + ZOMBIE_VILLAGER(EntityType.ZOMBIE_VILLAGER, new PotionEffect(PotionEffectType.REGENERATION, 20 * 10, 0)), + ENDER_DRAGON(EntityType.ENDER_DRAGON, new PotionEffect(PotionEffectType.HEALTH_BOOST, 20 * 10, 5)), + ZOMBIE_HORSE(EntityType.ZOMBIE_HORSE, new PotionEffect(PotionEffectType.HEALTH_BOOST, 20 * 10, 1)), + BEE(EntityType.BEE, new PotionEffect(PotionEffectType.SPEED, 20 * 10, 1)), + + ; + + @Getter private final EntityType entityType; + @Getter private final PotionEffect potionEffect; +} + diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 56e56b0..4c889cc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: lee.code.pets.Pets description: $description author: Lee api-version: "$apiVersion" -depend: [ProtocolLib, GoldmanEconomy, GoldmanColors, GoldmanPlayerData] +depend: [ProtocolLib, GoldmanPlayerData] commands: pets: description: Main pets command.