diff --git a/.gitignore b/.gitignore index 72578b3..7afb5fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Don't track content of these folders .idea/* target/* +1_17_R1/target/* +Plugin/target/* +Utility/target/* # Compiled source # ################### diff --git a/1.14 TRANS.xlsx b/1.14 TRANS.xlsx deleted file mode 100644 index 13163dd..0000000 Binary files a/1.14 TRANS.xlsx and /dev/null differ diff --git a/1_17_R1/pom.xml b/1_17_R1/pom.xml new file mode 100644 index 0000000..6b7c740 --- /dev/null +++ b/1_17_R1/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + + net.seanomik + tamablefoxes-parent + 2.0.0-SNAPSHOT + + + tamablefoxes_v1_17_R1 + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + + + + + + net.seanomik + tamablefoxes-util + ${project.parent.version} + provided + + + org.spigotmc + spigot + 1.17-R0.1-SNAPSHOT + provided + + + net.wesjd + anvilgui + 1.5.1-SNAPSHOT + + + \ No newline at end of file diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java new file mode 100644 index 0000000..3ad8f4c --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/EntityTamableFox.java @@ -0,0 +1,598 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1; + +import net.minecraft.advancements.CriterionTriggers; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.syncher.DataWatcher; +import net.minecraft.network.syncher.DataWatcherObject; +import net.minecraft.network.syncher.DataWatcherRegistry; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.EnumHand; +import net.minecraft.world.EnumInteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.*; +import net.minecraft.world.entity.ai.goal.*; +import net.minecraft.world.entity.ai.goal.target.PathfinderGoalNearestAttackableTarget; +import net.minecraft.world.entity.animal.*; +import net.minecraft.world.entity.animal.horse.EntityHorseAbstract; +import net.minecraft.world.entity.monster.EntityCreeper; +import net.minecraft.world.entity.monster.EntityGhast; +import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.entity.player.PlayerAbilities; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemMonsterEgg; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.World; +import net.minecraft.world.scores.ScoreboardTeamBase; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.IEntitySelector; +import net.minecraft.world.entity.ai.goal.PathfinderGoal; +import net.minecraft.world.entity.animal.EntityFox; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding.*; +import net.wesjd.anvilgui.AnvilGUI; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Server; +import org.bukkit.craftbukkit.libs.jline.internal.Nullable; +import org.bukkit.craftbukkit.v1_17_R1.CraftServer; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityRegainHealthEvent; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.function.Predicate; + +public class EntityTamableFox extends EntityFox { + + protected static final DataWatcherObject tamed; + protected static final DataWatcherObject> ownerUUID; + + private static final DataWatcherObject bw; // DATA_FLAGS_ID + private static final Predicate bC; // AVOID_PLAYERS + + static { + tamed = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.a); + ownerUUID = DataWatcher.a(EntityTamableFox.class, DataWatcherRegistry.o); + + bw = DataWatcher.a(EntityFox.class, DataWatcherRegistry.a); + bC = (entity) -> !entity.isSneaking() && IEntitySelector.e.test(entity); + } + + List untamedGoals; + private FoxPathfinderGoalSit goalSit; + + public EntityTamableFox(EntityTypes entitytypes, World world) { + super(entitytypes, world); + + System.out.println("Set default attributes"); + /*this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.33000001192092896D); + if (isTamed()) { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(24.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(3.0D); + this.setHealth(this.getMaxHealth()); + } else { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(10.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D); + }*/ + } + + @Override + public void initPathfinder() { + try { + this.goalSit = new FoxPathfinderGoalSit(this); + this.bO.a(1, goalSit); + + // Wild animal attacking + Field landTargetGoal = this.getClass().getSuperclass().getDeclaredField("cj"); // landTargetGoal + landTargetGoal.setAccessible(true); + landTargetGoal.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityAnimal.class, 10, false, false, (entityliving) -> { + return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && (entityliving instanceof EntityChicken || entityliving instanceof EntityRabbit); + })); + + Field turtleEggTargetGoal = this.getClass().getSuperclass().getDeclaredField("ck"); // turtleEggTargetGoal + turtleEggTargetGoal.setAccessible(true); + turtleEggTargetGoal.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityTurtle.class, 10, false, false, EntityTurtle.bT)); + + Field fishTargetGoal = this.getClass().getSuperclass().getDeclaredField("cl"); // fishTargetGoal + fishTargetGoal.setAccessible(true); + fishTargetGoal.set(this, new PathfinderGoalNearestAttackableTarget(this, EntityFish.class, 20, false, false, (entityliving) -> { + return (!isTamed() || (Config.doesTamedAttackWildAnimals() && isTamed())) && entityliving instanceof EntityFishSchool; + })); + + this.goalSelector().a(0, getFoxInnerPathfinderGoal("g")); // FoxFloatGoal + this.goalSelector().a(1, getFoxInnerPathfinderGoal("b")); // FaceplantGoal + this.goalSelector().a(2, new FoxPathfinderGoalPanic(this, 2.2D)); + this.goalSelector().a(2, new FoxPathfinderGoalSleepWithOwner(this)); + this.goalSelector().a(3, getFoxInnerPathfinderGoal("e", Arrays.asList(1.0D), Arrays.asList(double.class))); // FoxBreedGoal + + this.goalSelector().a(4, new PathfinderGoalAvoidTarget(this, EntityHuman.class, 16.0F, 1.6D, 1.4D, (entityliving) -> { + return !isTamed() && bC.test((EntityLiving) entityliving) && !this.isDefending(); + })); + this.goalSelector().a(4, new PathfinderGoalAvoidTarget(this, EntityWolf.class, 8.0F, 1.6D, 1.4D, (entityliving) -> { + return !((EntityWolf)entityliving).isTamed() && !this.isDefending(); + })); + this.goalSelector().a(4, new PathfinderGoalAvoidTarget(this, EntityPolarBear.class, 8.0F, 1.6D, 1.4D, (entityliving) -> { + return !this.isDefending(); + })); + + this.goalSelector().a(5, getFoxInnerPathfinderGoal("u")); // StalkPreyGoal + this.goalSelector().a(6, new o()); // FoxPounceGoal + this.goalSelector().a(7, getFoxInnerPathfinderGoal("l", Arrays.asList(1.2000000476837158D, true), Arrays.asList(double.class, boolean.class))); // FoxMeleeAttackGoal + this.goalSelector().a(8, getFoxInnerPathfinderGoal("h", Arrays.asList(this, 1.25D), Arrays.asList(EntityFox.class, double.class))); // FoxFollowParentGoal + this.goalSelector().a(8, new FoxPathfinderGoalSleepWithOwner(this)); + this.goalSelector().a(9, new FoxPathfinderGoalFollowOwner(this, 1.3D, 10.0F, 2.0F, false)); + this.goalSelector().a(10, new PathfinderGoalLeapAtTarget(this, 0.4F)); + this.goalSelector().a(11, new PathfinderGoalRandomStrollLand(this, 1.0D)); + this.goalSelector().a(11, getFoxInnerPathfinderGoal("p")); // FoxSearchForItemsGoal + this.goalSelector().a(12, getFoxInnerPathfinderGoal("j", Arrays.asList(this, EntityHuman.class, 24.0f), + Arrays.asList(EntityInsentient.class, Class.class, float.class))); // LookAtPlayer + + this.targetSelector().a(1, new FoxPathfinderGoalOwnerHurtByTarget(this)); + this.targetSelector().a(2, new FoxPathfinderGoalOwnerHurtTarget(this)); + this.targetSelector().a(3, (new FoxPathfinderGoalHurtByTarget(this)).a(new Class[0])); + + // Assign all the untamed goals that will later be removed. + untamedGoals = new ArrayList<>(); + + // SleepGoal + PathfinderGoal sleep = getFoxInnerPathfinderGoal("t"); + this.goalSelector().a(7, sleep); + untamedGoals.add(sleep); + + // PerchAndSearch (Random sitting?) + PathfinderGoal perchAndSearch = getFoxInnerPathfinderGoal("r"); + this.goalSelector().a(13, perchAndSearch); + untamedGoals.add(perchAndSearch); + + // FoxEatBerriesGoal (Pick berry bushes) + PathfinderGoal eatBerries = new f(1.2000000476837158D, 12, 2); + this.goalSelector().a(11, eatBerries); + untamedGoals.add(eatBerries); // Maybe this should be configurable too? + + // SeekShelterGoal + PathfinderGoal seekShelter = getFoxInnerPathfinderGoal("s", Arrays.asList(1.25D), Arrays.asList(double.class)); + this.goalSelector().a(6, seekShelter); + untamedGoals.add(seekShelter); + + // StrollThroughVillage + PathfinderGoal strollThroughVillage = getFoxInnerPathfinderGoal("q", Arrays.asList(32, 200), Arrays.asList(int.class, int.class)); + this.goalSelector().a(9, strollThroughVillage); + untamedGoals.add(strollThroughVillage); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private DataWatcher datawatcher() { + return this.Y; + } + + private PathfinderGoalSelector goalSelector() { + return this.bO; + } + + private PathfinderGoalSelector targetSelector() { + return this.bP; + } + + private Random random() { + return this.Q; + } + + // deobf: 'getFlag' + private boolean u(int i) { + return ((Byte)datawatcher().get(bw) & i) != 0; + } + + // deobf: 'isDefending' from 'fI' + public boolean isDefending() { + return this.u(128); + } + + public static Object getPrivateField(String fieldName, Class clazz, Object object) { + Field field; + Object o = null; + + try { + field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + o = field.get(object); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + + return o; + } + + protected void initDatawatcher() { + super.initDatawatcher(); + this.datawatcher().register(tamed, (byte) 0); + this.datawatcher().register(ownerUUID, Optional.empty()); + } + + @Override + public void saveData(NBTTagCompound compound) { + super.saveData(compound); + if (this.getOwnerUUID() == null) { + compound.setString("OwnerUUID", ""); + } else { + compound.setString("OwnerUUID", this.getOwnerUUID().toString()); + } + + compound.setBoolean("Sitting", this.isSitting()); + } + + @Override + public void loadData(NBTTagCompound compound) { + super.loadData(compound); + String ownerUuid = ""; + + if (compound.hasKeyOfType("OwnerUUID", 8)) { + ownerUuid = compound.getString("OwnerUUID"); + }/* else { + String var2 = compound.getString("Owner"); + ownerUuid = NameReferencingFileConverter.a(this.getMinecraftServer(), var2); + }*/ + + if (!ownerUuid.isEmpty()) { + try { + this.setOwnerUUID(UUID.fromString(ownerUuid)); + this.setTamed(true); + } catch (Throwable throwable) { + this.setTamed(false); + } + } + + if (this.goalSit != null) { + this.goalSit.setSitting(compound.getBoolean("Sitting")); + } + + this.setSitting(compound.getBoolean("Sitting")); + } + + public boolean isTamed() { + return ((Byte) this.datawatcher().get(tamed) & 4) != 0; + } + + public void setTamed(boolean tamed_) { + byte isTamed = this.datawatcher().get(tamed); + if (tamed_) { + this.datawatcher().set(tamed, (byte) (isTamed | 4)); + } else { + this.datawatcher().set(tamed, (byte) (isTamed & -5)); + } + this.reassessTameGoals(); + + System.out.println("setTamed set attributes"); + /*if (tamed_) { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(24.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(3.0D); + this.setHealth(this.getMaxHealth()); + } else { + this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(10.0D); + this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D); + }*/ + } + + // Remove untamed goals if its tamed. + private void reassessTameGoals() { + if (!isTamed()) return; + + for (PathfinderGoal untamedGoal : untamedGoals) { + this.goalSelector().a(untamedGoal); + } + } + + // mobInteract + @Override + public EnumInteractionResult b(EntityHuman entityhuman, EnumHand enumhand) { + ItemStack itemstack = entityhuman.b(enumhand); + Item item = itemstack.getItem(); + + if (itemstack.getItem() instanceof ItemMonsterEgg) { + return super.b(entityhuman, enumhand); + } else { + if (this.isTamed()) { + + // Heal the fox if its health is below the max. + if (item.isFood() && item.getFoodInfo().c() && this.getHealth() < this.getMaxHealth()) { + // Only remove the item from the player if they're in survival mode. + Player player = (Player) entityhuman.getBukkitEntity(); + if (player.getGameMode() != GameMode.CREATIVE ) { + itemstack.subtract(1); + } + + this.heal((float)item.getFoodInfo().getNutrition(), EntityRegainHealthEvent.RegainReason.EATING); + return EnumInteractionResult.b; // CONSUME + } + + if (isOwnedBy(entityhuman)) { + // This super method checks if the fox can breed or not. + EnumInteractionResult flag = super.b(entityhuman, enumhand); + + // If the player is not sneaking and the fox cannot breed, then make the fox sit. + // @TODO: Do I need to use this.eQ() instead of flag != EnumInteractionResult.SUCCESS? + // EnumInteractionResult.a = EnumInteractionResult.SUCCESS + if (!entityhuman.isSneaking() && (flag != EnumInteractionResult.a || this.isBaby())) { + this.setSleeping(false); + this.goalSit.setSitting(!this.isSitting()); + return flag; + } else if (entityhuman.isSneaking() && enumhand == EnumHand.a) { // EnumHand.a = EnumHand.MAIN_HAND; Swap/Put/Take item from fox. + // Ignore buckets since they can be easily duplicated. + // nW = BUCKET; nX = WATER_BUCKET; nY = LAVA_BUCKET + if (itemstack.getItem() == Items.nW || itemstack.getItem() == Items.nX || itemstack.getItem() == Items.nY) { + return EnumInteractionResult.c; // EnumInteractionResult.c = EnumInteractionResult.PASS + } + + // Check if the player has something in their main hand. + // EnumItemSlot.MAINHAND = EnumItemSlot.a + if (!this.getEquipment(EnumItemSlot.a).isEmpty()) { + getBukkitEntity().getWorld().dropItem(getBukkitEntity().getLocation(), CraftItemStack.asBukkitCopy(this.getEquipment(EnumItemSlot.a))); + this.setSlot(EnumItemSlot.a, new ItemStack(Items.a)); // Items.a = AIR + } + + // Run this task async to make sure to not slow the server down. + // This is needed due to the item being remove as soon as its put in the foxes mouth. + Bukkit.getScheduler().runTaskLaterAsynchronously(Utils.tamableFoxesPlugin, ()-> { + // Put item in mouth + if (item != Items.a) { // Items.a = AIR + ItemStack c = itemstack.cloneItemStack(); + c.setCount(1); + + // Only remove the item from the player if they're in survival mode. + Player player = (Player) entityhuman.getBukkitEntity(); + if (player.getGameMode() != GameMode.CREATIVE ) { + itemstack.subtract(1); + } + + this.setSlot(EnumItemSlot.a, c); + } + // If the player doesn't have anything in their hand, make the fox sleep or wakeup. + else { + this.goalSit.setSitting(false); + this.setSleeping(!this.isSleeping()); + } + }, (long) 0.1); + + return EnumInteractionResult.a; + //return true; + } + } + } else if (item == Items.px) { // px = CHICKEN + // Check if the player has permissions to tame the fox + if (Config.canPlayerTameFox((Player) entityhuman.getBukkitEntity())) { + // Only remove the item from the player if they're in survival mode. + Player player = (Player) entityhuman.getBukkitEntity(); + if (player.getGameMode() != GameMode.CREATIVE ) { + itemstack.subtract(1); + } + + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(Utils.tamableFoxesPlugin); + int maxTameCount = Config.getMaxPlayerFoxTames(); + if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { + ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); + + return EnumInteractionResult.a; + } + + // 0.33% chance to tame the fox, also check if the called tame entity event is cancelled or not. + if (this.getRandom().nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { + this.tame(entityhuman); + + // Remove all navigation when tamed. + this.bN.o(); // bN = navigation + this.setGoalTarget(null); + this.goalSit.setSitting(true); + + if (maxTameCount > 0) { + sqLiteHelper.addPlayerFoxAmount(entityhuman.getUniqueID(), 1); + } + + getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.HEART, getBukkitEntity().getLocation(), 6, 0.5D, 0.5D, 0.5D); + + // Give player tamed message. + ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamedMessage()); + + // Let the player choose the new fox's name if its enabled in config. + if (Config.askForNameAfterTaming()) { + player.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getTamingAskingName()); + new AnvilGUI.Builder() + .onComplete((plr, input) -> { // Called when the inventory output slot is clicked + if (!input.equals("")) { + org.bukkit.entity.Entity tamableFox = this.getBukkitEntity(); + + // This will auto format the name for config settings. + String foxName = LanguageConfig.getFoxNameFormat(input, player.getDisplayName()); + + tamableFox.setCustomName(foxName); + tamableFox.setCustomNameVisible(true); + plr.sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getTamingChosenPerfect(input)); + } + + return AnvilGUI.Response.close(); + }) + .text("Fox name") // Sets the text the GUI should start with + .plugin(Utils.tamableFoxesPlugin) // Set the plugin instance + .open(player); // Opens the GUI for the player provided + } + } else { + getBukkitEntity().getWorld().spawnParticle(org.bukkit.Particle.SMOKE_NORMAL, getBukkitEntity().getLocation(), 10, 0.2D, 0.2D, 0.2D, 0.15D); + } + } + + return EnumInteractionResult.a; + } + + return super.b(entityhuman, enumhand); + } + } + + @Override + public EntityTamableFox createChild(WorldServer worldserver, EntityAgeable entityageable) { + EntityTamableFox entityfox = (EntityTamableFox) EntityTypes.E.a(worldserver); // EntityTypes.E = EntityTypes.FOX + entityfox.setFoxType(this.getRandom().nextBoolean() ? this.getFoxType() : ((EntityFox)entityageable).getFoxType()); + + UUID uuid = this.getOwnerUUID(); + if (uuid != null) { + entityfox.setOwnerUUID(uuid); + entityfox.setTamed(true); + } + + return entityfox; + } + + @Override + public boolean mate(EntityAnimal entityanimal) { + if (entityanimal == this) { + return false; + } else if (!(entityanimal instanceof EntityTamableFox)) { + return false; + } else { + EntityTamableFox entityFox = (EntityTamableFox) entityanimal; + return (!entityFox.isSitting() && (this.isInLove() && entityFox.isInLove())); + } + } + + @Nullable + public UUID getOwnerUUID() { + return (UUID) ((Optional) this.datawatcher().get(ownerUUID)).orElse(null); + } + + public void setOwnerUUID(@Nullable UUID ownerUuid) { + this.datawatcher().set(ownerUUID, Optional.ofNullable(ownerUuid)); + } + + public void tame(EntityHuman owner) { + this.setTamed(true); + this.setOwnerUUID(owner.getUniqueID()); + + // Give the player the taming advancement. + if (owner instanceof EntityPlayer) { + CriterionTriggers.x.a((EntityPlayer)owner, this); + } + } + + @Nullable + public EntityLiving getOwner() { + try { + UUID ownerUuid = this.getOwnerUUID(); + return ownerUuid == null ? null : this.getWorld().b(ownerUuid); + } catch (IllegalArgumentException var2) { + return null; + } + } + + // Only attack entity if its not attacking owner. + // canAttack + @Override + public boolean c(EntityLiving entity) { + return !this.isOwnedBy(entity) && super.c(entity); + } + + public boolean isOwnedBy(EntityLiving entity) { + return entity == this.getOwner(); + } + + /* + deobf: wantsToAttack (Copied from EntityWolf) + This code being from EntityWolf also means that wolves will want to attack foxes + Our life would be so much easier if we could extend both EntityFox and EntityTameableAnimal + */ + public boolean wantsToAttack(EntityLiving entityliving, EntityLiving entityliving1) { + if (!(entityliving instanceof EntityCreeper) && !(entityliving instanceof EntityGhast)) { + if (entityliving instanceof EntityTamableFox) { + EntityTamableFox entityFox = (EntityTamableFox) entityliving; + return !entityFox.isTamed() || entityFox.getOwner() != entityliving1; + } else { + return (!(entityliving instanceof EntityHuman) + || !(entityliving1 instanceof EntityHuman) || + ((EntityHuman) entityliving1).a((EntityHuman) entityliving)) && ((!(entityliving instanceof EntityHorseAbstract) + || !((EntityHorseAbstract) entityliving).isTamed()) && (!(entityliving instanceof EntityTameableAnimal) + || !((EntityTameableAnimal) entityliving).isTamed())); + } + } else { + return false; + } + } + + // Set the scoreboard team to the same as the owner if its tamed. + public ScoreboardTeamBase getScoreboardTeam() { + if (this.isTamed()) { + EntityLiving var0 = this.getOwner(); + if (var0 != null) { + return var0.getScoreboardTeam(); + } + } + + return super.getScoreboardTeam(); + } + + // Override isAlliedTo (Entity::r(Entity)) + public boolean r(Entity entity) { + if (this.isTamed()) { + EntityLiving entityOwner = this.getOwner(); + if (entity == entityOwner) { + return true; + } + + if (entityOwner != null) { + return entityOwner.r(entity); + } + } + return super.r(entity); + } + + // When the fox dies, show a chat message. + public void die(DamageSource damageSource) { + // getWorld().y = getWorld().isClientSide; GameRules.m = GameRules.SHOW_DEATH_MESSAGES + if (!this.getWorld().y && this.getWorld().getGameRules().getBoolean(GameRules.m) && this.getOwner() instanceof EntityPlayer) { + this.getOwner().sendMessage(this.getCombatTracker().getDeathMessage(), getOwnerUUID()); + + // Remove the amount of foxes the player has tamed if the limit is enabled. + if (Config.getMaxPlayerFoxTames() > 0) { + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(Utils.tamableFoxesPlugin); + sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); + } + } + + super.die(damageSource); + } + + + private PathfinderGoal getFoxInnerPathfinderGoal(String innerName, List args, List> argTypes) { + return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, args, argTypes); + } + + private PathfinderGoal getFoxInnerPathfinderGoal(String innerName) { + return (PathfinderGoal) Utils.instantiatePrivateInnerClass(EntityFox.class, innerName, this, Arrays.asList(), Arrays.asList()); + } + + private void clearPathFinderGoals() { + Set goalSet = (Set) getPrivateField("d", PathfinderGoalSelector.class, goalSelector()); + Set targetSet = (Set) getPrivateField("d", PathfinderGoalSelector.class, targetSelector()); + goalSet.clear(); + targetSet.clear(); + + Map goalMap = (Map) getPrivateField("c", PathfinderGoalSelector.class, goalSelector()); + Map targetMap = (Map) getPrivateField("c", PathfinderGoalSelector.class, targetSelector()); + goalMap.clear(); + targetMap.clear(); + + EnumSet goalEnumSet = (EnumSet) getPrivateField("f", PathfinderGoalSelector.class, goalSelector()); + EnumSet targetEnumSet = (EnumSet) getPrivateField("f", PathfinderGoalSelector.class, targetSelector()); + goalEnumSet.clear(); + targetEnumSet.clear(); + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java new file mode 100644 index 0000000..d6d43fe --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/NMSInterface_1_17_R1.java @@ -0,0 +1,42 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1; + +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.animal.EntityFox; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class NMSInterface_1_17_R1 implements NMSInterface { + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.E.getClass().getDeclaredField("bm"); + + //FOX = a("fox", EntityTypes.Builder.a(EntityFox::new, EnumCreatureType.CREATURE).a(0.6F, 0.7F).trackingRange(8).a(Blocks.SWEET_BERRY_BUSH)); + /*Method method = EntityTypes.class.getDeclaredMethod("a", String.class, EntityTypes.Builder.class); + method.setAccessible(true); + EntityTypes type = method.invoke(null, "fox", EntityTypes.Builder.a(EntityTamableFox::new, EnumCreatureType.C))*/ + + FieldHelper.setField(field, EntityTypes.E, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.a : EntityFox.Type.b); + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalFollowOwner.java new file mode 100644 index 0000000..f766190 --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -0,0 +1,149 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.core.BlockPosition; +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.ai.goal.PathfinderGoal; +import net.minecraft.world.entity.ai.navigation.Navigation; +import net.minecraft.world.entity.ai.navigation.NavigationAbstract; +import net.minecraft.world.entity.ai.navigation.NavigationFlying; +import net.minecraft.world.level.IWorldReader; +import net.minecraft.world.level.block.BlockLeaves; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.pathfinder.PathType; +import net.minecraft.world.level.pathfinder.PathfinderNormal; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityLiving b; + private final IWorldReader c; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + private final boolean j; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { + this.a = tamableFox; + this.c = tamableFox.getWorld(); + this.d = d0; + this.e = tamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.j = flag; + this.a(EnumSet.of(Type.a, Type.b)); // a = MOVE; b = LOOK + if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving.isSpectator()) { + return false; + } else if (this.a.isSitting()) { // this.a.isWillSit() + return false; + } else if (this.a.f(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.b = entityliving; + return true; + } + } + + public boolean b() { + // Simplified with IntelliJ hints + return !this.e.m() && (!this.a.isSitting() && this.a.f(this.f) > (double) (this.g * this.g)); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.i); + this.a.a(PathType.i, 0.0F); + } + + public void d() { + this.b = null; + this.e.o(); + this.a.a(PathType.i, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.eY()); + if (--this.f <= 0) { + this.f = 10; + if (!this.a.isLeashed() && !this.a.isPassenger()) { + if (this.a.f(this.b) >= 144.0D) { + this.g(); + } else { + this.e.a(this.b, this.d); + } + } + } + + } + + private void g() { + BlockPosition blockposition = this.b.getChunkCoordinates(); + + for(int i = 0; i < 10; ++i) { + int j = this.a(-3, 3); + int k = this.a(-1, 1); + int l = this.a(-3, 3); + boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); + if (flag) { + return; + } + } + + } + + private boolean a(int i, int j, int k) { + if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { + return false; + } else if (!this.a(new BlockPosition(i, j, k))) { + return false; + } else { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.getYRot(), this.a.getXRot()); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.getWorld().getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } else { + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return true; + } + } + } + + private boolean a(BlockPosition blockposition) { + PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); + if (pathtype != PathType.c) { + return false; + } else { + IBlockData iblockdata = this.c.getType(blockposition.down()); + if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { + return false; + } else { + BlockPosition blockposition1 = blockposition.e(this.a.getChunkCoordinates()); + return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); + } + } + } + + private int a(int i, int j) { + return this.a.getRandom().nextInt(j - i + 1) + i; + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java new file mode 100644 index 0000000..6f95041 --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java @@ -0,0 +1,121 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.EntityInsentient; +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.IEntitySelector; +import net.minecraft.world.entity.ai.goal.target.PathfinderGoalTarget; +import net.minecraft.world.entity.ai.targeting.PathfinderTargetCondition; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.phys.AxisAlignedBB; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; + +public class FoxPathfinderGoalHurtByTarget extends PathfinderGoalTarget { + private static final PathfinderTargetCondition a = PathfinderTargetCondition.a().d().e(); + private boolean b; + private int c; + private final Class[] d; + private Class[] i; + + public FoxPathfinderGoalHurtByTarget(EntityTamableFox tamableFox, Class... aclass) { + super(tamableFox, true); + this.d = aclass; + this.a(EnumSet.of(Type.d)); + } + + public boolean a() { + int i = this.e.dH(); + EntityLiving entityliving = this.e.getLastDamager(); + if (i != this.c && entityliving != null) { + if (entityliving.getEntityType() == EntityTypes.bi && this.e.getWorld().getGameRules().getBoolean(GameRules.I)) { + return false; + } else { + Class[] aclass = this.d; + int j = aclass.length; + + for(int k = 0; k < j; ++k) { + Class oclass = aclass[k]; + if (oclass.isAssignableFrom(entityliving.getClass())) { + return false; + } + } + + return this.a(entityliving, a); + } + } else { + return false; + } + } + + public FoxPathfinderGoalHurtByTarget a(Class... aclass) { + this.b = true; + this.i = aclass; + return this; + } + + public void c() { + this.e.setGoalTarget(this.e.getLastDamager(), TargetReason.TARGET_ATTACKED_ENTITY, true); + this.g = this.e.getGoalTarget(); + this.c = this.e.dH(); + this.h = 300; + if (this.b) { + this.g(); + } + + super.c(); + } + + protected void g() { + double d0 = this.k(); + AxisAlignedBB axisalignedbb = AxisAlignedBB.a(this.e.getPositionVector()).grow(d0, 10.0D, d0); + List list = this.e.getWorld().a(this.e.getClass(), axisalignedbb, IEntitySelector.f); + Iterator iterator = list.iterator(); + + while(true) { + EntityInsentient entityinsentient; + boolean flag; + do { + do { + do { + do { + do { + if (!iterator.hasNext()) { + return; + } + + entityinsentient = (EntityInsentient)iterator.next(); + } while(this.e == entityinsentient); + } while(entityinsentient.getGoalTarget() != null); + } while(this.e instanceof EntityTamableFox && ((EntityTamableFox)this.e).getOwner() != ((EntityTamableFox)entityinsentient).getOwner()); + } while(entityinsentient.r(this.e.getLastDamager())); + + if (this.i == null) { + break; + } + + flag = false; + Class[] aclass = this.i; + int i = aclass.length; + + for(int j = 0; j < i; ++j) { + Class oclass = aclass[j]; + if (entityinsentient.getClass() == oclass) { + flag = true; + break; + } + } + } while(flag); + + this.a(entityinsentient, this.e.getLastDamager()); + } + } + + protected void a(EntityInsentient entityinsentient, EntityLiving entityliving) { + entityinsentient.setGoalTarget(entityliving, TargetReason.TARGET_ATTACKED_NEARBY_ENTITY, true); + } +} \ No newline at end of file diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java new file mode 100644 index 0000000..7a4628a --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -0,0 +1,46 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.ai.goal.target.PathfinderGoalTarget; +import net.minecraft.world.entity.ai.targeting.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.d)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.dH(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.wantsToAttack(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.dH(); + } + + super.c(); + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java new file mode 100644 index 0000000..71d5bcc --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -0,0 +1,46 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.ai.goal.target.PathfinderGoalTarget; +import net.minecraft.world.entity.ai.targeting.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.d)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.dI(); + int i = entityliving.dJ(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.wantsToAttack(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.dJ(); + } + + super.c(); + } +} \ No newline at end of file diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java new file mode 100644 index 0000000..4d811c9 --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalPanic.java @@ -0,0 +1,17 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.ai.goal.PathfinderGoalPanic; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; + +public class FoxPathfinderGoalPanic extends PathfinderGoalPanic { + EntityTamableFox tamableFox; + + public FoxPathfinderGoalPanic(EntityTamableFox tamableFox, double d0) { + super(tamableFox, d0); + this.tamableFox = tamableFox; + } + + public boolean a() { + return !tamableFox.isDefending() && super.a(); + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSit.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSit.java new file mode 100644 index 0000000..539af6f --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSit.java @@ -0,0 +1,59 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.ai.goal.PathfinderGoal; +import net.minecraft.world.level.block.Blocks; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.Bukkit; + +import java.util.EnumSet; + +public class FoxPathfinderGoalSit extends PathfinderGoal { + private final EntityTamableFox entity; + private boolean willSit; + + public FoxPathfinderGoalSit(EntityTamableFox tamableFox) { + this.entity = tamableFox; + this.a(EnumSet.of(Type.c, Type.a)); // c = JUMP; a = MOVE + } + + public boolean b() { + return this.willSit; + } + + private boolean isInBubbleColumn() { + return this.entity.getWorld().getType(this.entity.getChunkCoordinates()).a(Blocks.lq); + } + + public boolean a() { + if (!this.entity.isTamed()) { + return this.willSit && this.entity.getGoalTarget() == null; + } else if (this.entity.aO()) { + return false; + } else if (!this.entity.isOnGround()) { + return false; + } else { + EntityLiving entityliving = this.entity.getOwner(); + return entityliving == null || ((!(this.entity.f(entityliving) < 144.0D) || entityliving.getLastDamager() == null) && this.willSit); + } + } + + public void c() { + this.entity.getNavigation().o(); + this.entity.setGoalTarget(null); + + // For some reason it needs to be ran later to not have the fox slide across the floor. + Bukkit.getScheduler().runTaskLater(Utils.tamableFoxesPlugin, () -> { + this.entity.setSitting(true); + }, 1L); + } + + public void d() { + this.entity.setSitting(false); + } + + public void setSitting(boolean flag) { + this.willSit = flag; + } +} diff --git a/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java new file mode 100644 index 0000000..9505da7 --- /dev/null +++ b/1_17_R1/src/main/java/net/seanomik/tamablefoxes/versions/version_1_17_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -0,0 +1,153 @@ +package net.seanomik.tamablefoxes.versions.version_1_17_R1.pathfinding; + +import net.minecraft.core.BlockPosition; +import net.minecraft.server.level.WorldServer; +import net.minecraft.tags.TagsBlock; +import net.minecraft.util.MathHelper; +import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.ai.goal.PathfinderGoal; +import net.minecraft.world.entity.item.EntityItem; +import net.minecraft.world.entity.player.EntityHuman; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.BlockBed; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.LootTables; +import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSets; +import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; +import net.minecraft.world.phys.AxisAlignedBB; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityDropItemEvent; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +// From class EntityCat#b +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox entitycat) { + this.a = entitycat; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman) entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.f(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = this.b.getChunkCoordinates(); + IBlockData iblockdata = this.a.getWorld().getType(blockposition); + if (iblockdata.a(TagsBlock.L)) { + this.c = (BlockPosition) iblockdata.d(BlockBed.aE).map((enumdirection) -> { + return blockposition.shift(enumdirection.opposite()); + }).orElseGet(() -> { + return new BlockPosition(blockposition); + }); + return !this.g(); + } + } + + } + return false; + } + + private boolean g() { + List list = this.a.getWorld().a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entitycat; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entitycat = (EntityTamableFox)iterator.next(); + } while(entitycat == this.a); + } while(!entitycat.isSleeping()); + + return true; + } + + public boolean b() { + return this.a.isTamed() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.getWorld().f(1.0F); + if (this.b.fm() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.getWorld().getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.y(false); + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + LootTable loottable = this.a.t.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); + net.minecraft.world.level.storage.loot.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.world.level.storage.loot.LootTableInfo.Builder((WorldServer)this.a.t)).set(LootContextParameters.f, this.a.getPositionVector()).set(LootContextParameters.a, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.g)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + EntityItem entityitem = new EntityItem(this.a.t, (double)blockposition_mutableblockposition.getX() - (double) MathHelper.sin(this.a.aX * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aX * 0.017453292F), itemstack); + EntityDropItemEvent event = new EntityDropItemEvent(this.a.getBukkitEntity(), (org.bukkit.entity.Item)entityitem.getBukkitEntity()); + entityitem.t.getCraftServer().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + this.a.t.addEntity(entityitem); + } + } + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.f(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.y(false); + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.y(true); + } + } else { + this.a.setSleeping(false); + } + } + + } +} diff --git a/Spigot_v14_v15_v16-v165.jar b/Plugin/Spigot_v14_v15_v16-v165.jar similarity index 100% rename from Spigot_v14_v15_v16-v165.jar rename to Plugin/Spigot_v14_v15_v16-v165.jar diff --git a/Plugin/output.jar b/Plugin/output.jar new file mode 100644 index 0000000..791f72f Binary files /dev/null and b/Plugin/output.jar differ diff --git a/Plugin/pom.xml b/Plugin/pom.xml new file mode 100644 index 0000000..c6fdad3 --- /dev/null +++ b/Plugin/pom.xml @@ -0,0 +1,119 @@ + + + + 4.0.0 + + net.seanomik + tamablefoxes-parent + 2.0.0-SNAPSHOT + + + net.seanomik + tamablefoxes + 2.0.0-SNAPSHOT + jar + + Tamablefoxes + + + 1.8 + UTF-8 + 1.17 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.3.0-SNAPSHOT + + + package + + shade + + + D:\Code\java\spigotPlugins\servers\${server.version}\plugins\TamableFoxes_v${project.version}.jar + false + + + + + + + + src/main/resources + true + + + + + + + + apache.snapshots + https://repository.apache.org/snapshots/ + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + + + + + + net.seanomik + tamablefoxes-util + ${project.parent.version} + compile + + + net.seanomik + tamablefoxes_v1_17_R1 + ${project.parent.version} + compile + + + local.spigot.nms + AllSpigotNMS + LATEST + system + ${project.basedir}/Spigot_v14_v15_v16-v165.jar + + + + org.spigotmc + spigot-api + 1.14-R0.1-SNAPSHOT + provided + + + net.wesjd + anvilgui + 1.5.1-SNAPSHOT + + + diff --git a/src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java similarity index 92% rename from src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java index 715e9d9..8db8eb0 100644 --- a/src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/CommandSpawnTamableFox.java @@ -1,79 +1,80 @@ -package net.seanomik.tamablefoxes; - -import net.seanomik.tamablefoxes.versions.NMSInterface; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -public class CommandSpawnTamableFox implements TabExecutor { - - private final TamableFoxes plugin; - - public CommandSpawnTamableFox(TamableFoxes plugin) { - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getOnlyRunPlayer()); - return true; - } - - if (!sender.hasPermission("tamablefoxes.spawntamablefox")) { - sender.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getNoPermMessage()); - return true; - } - - Player player = (Player) sender; - if (args.length != 0) { - switch (args[0]) { - case "red": - try { - plugin.nmsInterface.spawnTamableFox(player.getLocation(), NMSInterface.FoxType.RED); - player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(NMSInterface.FoxType.RED)); - } catch (Exception e) { - e.printStackTrace(); - player.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureSpawn()); - } - break; - case "snow": - try { - plugin.nmsInterface.spawnTamableFox(player.getLocation(), NMSInterface.FoxType.SNOW); - player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(NMSInterface.FoxType.SNOW)); - } catch (Exception e) { - e.printStackTrace(); - player.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureSpawn()); - } - break; - case "reload": - plugin.reloadConfig(); - LanguageConfig.getConfig().reloadConfig(); - player.sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getReloadMessage()); - break; - default: - player.sendMessage(ChatColor.RED + "/spawntamablefox " + ChatColor.GRAY + "[red | snow | reload]"); - } - } else { - player.sendMessage(ChatColor.RED + "/spawntamablefox " + ChatColor.GRAY + "[red | snow | reload]"); - } - - return true; - } - - @Override - public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { - return new LinkedList<>(Arrays.asList( - "red", - "snow", - "reload" - )); - } -} +package net.seanomik.tamablefoxes; + +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class CommandSpawnTamableFox implements TabExecutor { + + private final TamableFoxes plugin; + + public CommandSpawnTamableFox(TamableFoxes plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getOnlyRunPlayer()); + return true; + } + + if (!sender.hasPermission("tamablefoxes.spawntamablefox")) { + sender.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getNoPermMessage()); + return true; + } + + Player player = (Player) sender; + if (args.length != 0) { + switch (args[0]) { + case "red": + try { + plugin.nmsInterface.spawnTamableFox(player.getLocation(), NMSInterface.FoxType.RED); + player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(NMSInterface.FoxType.RED)); + } catch (Exception e) { + e.printStackTrace(); + player.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureSpawn()); + } + break; + case "snow": + try { + plugin.nmsInterface.spawnTamableFox(player.getLocation(), NMSInterface.FoxType.SNOW); + player.sendMessage(Utils.getPrefix() + ChatColor.RESET + LanguageConfig.getSpawnedFoxMessage(NMSInterface.FoxType.SNOW)); + } catch (Exception e) { + e.printStackTrace(); + player.sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureSpawn()); + } + break; + case "reload": + plugin.reloadConfig(); + LanguageConfig.getConfig(plugin).reloadConfig(); + player.sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getReloadMessage()); + break; + default: + player.sendMessage(ChatColor.RED + "/spawntamablefox " + ChatColor.GRAY + "[red | snow | reload]"); + } + } else { + player.sendMessage(ChatColor.RED + "/spawntamablefox " + ChatColor.GRAY + "[red | snow | reload]"); + } + + return true; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return new LinkedList<>(Arrays.asList( + "red", + "snow", + "reload" + )); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java similarity index 82% rename from src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index 446f1bc..f302290 100644 --- a/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -1,24 +1,20 @@ package net.seanomik.tamablefoxes; -import net.minecraft.server.v1_15_R1.EntityWolf; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; +import net.seanomik.tamablefoxes.versions.version_1_17_R1.NMSInterface_1_17_R1; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_14_R1.NMSInterface_1_14_R1; import net.seanomik.tamablefoxes.versions.version_1_15_R1.NMSInterface_1_15_R1; import net.seanomik.tamablefoxes.versions.version_1_16_R1.NMSInterface_1_16_R1; import net.seanomik.tamablefoxes.versions.version_1_16_R2.NMSInterface_1_16_R2; import net.seanomik.tamablefoxes.versions.version_1_16_R3.NMSInterface_1_16_R3; -import net.seanomik.tamablefoxes.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; import org.bukkit.*; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -// @TODO: - -/* @CHANGELOG (1.8.1-SNAPSHOT): - * Fixes #32. Kinda hacky but will work for now - */ public final class TamableFoxes extends JavaPlugin implements Listener { private static TamableFoxes plugin; @@ -29,8 +25,10 @@ public final class TamableFoxes extends JavaPlugin implements Listener { @Override public void onLoad() { plugin = this; + Utils.tamableFoxesPlugin = this; - LanguageConfig.getConfig().saveDefault(); + Config.setConfig(this.getConfig()); + LanguageConfig.getConfig(this).saveDefault(); // Verify server version String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; @@ -50,6 +48,9 @@ public final class TamableFoxes extends JavaPlugin implements Listener { case "v1_16_R3": nmsInterface = new NMSInterface_1_16_R3(); break; + case "v1_17_R1": + nmsInterface = new NMSInterface_1_17_R1(); + break; default: Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getUnsupportedMCVersionRegister()); Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + "You're trying to run MC version " + version + " which is not supported!"); @@ -62,7 +63,7 @@ public final class TamableFoxes extends JavaPlugin implements Listener { nmsInterface.registerCustomFoxEntity(); if (Config.getMaxPlayerFoxTames() != 0) { - SQLiteHelper.getInstance().createTablesIfNotExist(); + SQLiteHelper.getInstance(this).createTablesIfNotExist(); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java similarity index 98% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java index 1a11507..bb0ce8c 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/EntityTamableFox.java @@ -2,10 +2,10 @@ package net.seanomik.tamablefoxes.versions.version_1_14_R1; import net.minecraft.server.v1_14_R1.*; import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding.*; import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.Bukkit; @@ -17,7 +17,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityRegainHealthEvent; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.util.*; import java.util.function.Predicate; @@ -319,7 +318,7 @@ public class EntityTamableFox extends EntityFox { itemstack.subtract(1); } - SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); int maxTameCount = Config.getMaxPlayerFoxTames(); if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); @@ -500,7 +499,7 @@ public class EntityTamableFox extends EntityFox { // Remove the amount of foxes the player has tamed if the limit is enabled. if (Config.getMaxPlayerFoxTames() > 0) { - SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java similarity index 83% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java index 28d5d84..f917d76 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/NMSInterface_1_14_R1.java @@ -1,36 +1,35 @@ -package net.seanomik.tamablefoxes.versions.version_1_14_R1; - -import net.minecraft.server.v1_14_R1.EntityFox; -import net.minecraft.server.v1_14_R1.EntityTypes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.versions.FieldHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.entity.EntityType; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class NMSInterface_1_14_R1 implements NMSInterface { - @Override - public void registerCustomFoxEntity() { - try { // Replace the fox entity - Field field = EntityTypes.FOX.getClass().getDeclaredField("aZ"); - FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); - } catch (Exception e) { - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); - e.printStackTrace(); - } - } - - @Override - public void spawnTamableFox(Location loc, FoxType type) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); - tamableFox.setFoxType( (type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW ); - } -} +package net.seanomik.tamablefoxes.versions.version_1_14_R1; + +import net.minecraft.server.v1_14_R1.EntityFox; +import net.minecraft.server.v1_14_R1.EntityTypes; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; + +public class NMSInterface_1_14_R1 implements NMSInterface { + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.FOX.getClass().getDeclaredField("aZ"); + FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType( (type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW ); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index c88ee8f..9f71ce7 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -1,103 +1,103 @@ -package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; - -import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.event.entity.EntityTeleportEvent; - -import java.util.EnumSet; - -public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { - protected final EntityTamableFox a; - private EntityLiving c; - protected final IWorldReader b; - private final double d; - private final NavigationAbstract e; - private int f; - private final float g; - private final float h; - private float i; - - public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1) { - this.a = tamableFox; - this.b = tamableFox.world; - this.d = d0; - this.e = tamableFox.getNavigation(); - this.h = f; - this.g = f1; - this.a(EnumSet.of(Type.MOVE, Type.LOOK)); - if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { - throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); - } - } - - public boolean a() { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else if (entityliving instanceof EntityHuman && ((EntityHuman)entityliving).isSpectator()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { - return false; - } else { - this.c = entityliving; - return true; - } - } - - public boolean b() { - return !this.e.n() && this.a.h(this.c) > (double)(this.g * this.g) && !this.a.isSitting(); - } - - public void c() { - this.f = 0; - this.i = this.a.a(PathType.WATER); - this.a.a(PathType.WATER, 0.0F); - } - - public void d() { - this.c = null; - this.e.o(); - this.a.a(PathType.WATER, this.i); - } - - public void e() { - this.a.getControllerLook().a(this.c, 10.0F, (float)this.a.M()); - if (!this.a.isSitting() && --this.f <= 0) { - this.f = 10; - if (!this.e.a(this.c, this.d) && !this.a.isLeashed() && !this.a.isPassenger() && this.a.h(this.c) >= 144.0D) { - int i = MathHelper.floor(this.c.locX) - 2; - int j = MathHelper.floor(this.c.locZ) - 2; - int k = MathHelper.floor(this.c.getBoundingBox().minY); - - for(int l = 0; l <= 4; ++l) { - for(int i1 = 0; i1 <= 4; ++i1) { - if ((l < 1 || i1 < 1 || l > 3 || i1 > 3) && this.a(new BlockPosition(i + l, k - 1, j + i1))) { - CraftEntity entity = this.a.getBukkitEntity(); - Location to = new Location(entity.getWorld(), (double)((float)(i + l) + 0.5F), (double)k, (double)((float)(j + i1) + 0.5F), this.a.yaw, this.a.pitch); - EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); - this.a.world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - - to = event.getTo(); - this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - this.e.o(); - return; - } - } - } - } - } - - } - - protected boolean a(BlockPosition blockposition) { - IBlockData iblockdata = this.b.getType(blockposition); - return iblockdata.a(this.b, blockposition, this.a.getEntityType()) && this.b.isEmpty(blockposition.up()) && this.b.isEmpty(blockposition.up(2)); - } -} +package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; + +import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; +import net.minecraft.server.v1_14_R1.*; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + protected final EntityTamableFox a; + private EntityLiving c; + protected final IWorldReader b; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1) { + this.a = tamableFox; + this.b = tamableFox.world; + this.d = d0; + this.e = tamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.a(EnumSet.of(Type.MOVE, Type.LOOK)); + if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving instanceof EntityHuman && ((EntityHuman)entityliving).isSpectator()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.c = entityliving; + return true; + } + } + + public boolean b() { + return !this.e.n() && this.a.h(this.c) > (double)(this.g * this.g) && !this.a.isSitting(); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.WATER); + this.a.a(PathType.WATER, 0.0F); + } + + public void d() { + this.c = null; + this.e.o(); + this.a.a(PathType.WATER, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.c, 10.0F, (float)this.a.M()); + if (!this.a.isSitting() && --this.f <= 0) { + this.f = 10; + if (!this.e.a(this.c, this.d) && !this.a.isLeashed() && !this.a.isPassenger() && this.a.h(this.c) >= 144.0D) { + int i = MathHelper.floor(this.c.locX) - 2; + int j = MathHelper.floor(this.c.locZ) - 2; + int k = MathHelper.floor(this.c.getBoundingBox().minY); + + for(int l = 0; l <= 4; ++l) { + for(int i1 = 0; i1 <= 4; ++i1) { + if ((l < 1 || i1 < 1 || l > 3 || i1 > 3) && this.a(new BlockPosition(i + l, k - 1, j + i1))) { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)((float)(i + l) + 0.5F), (double)k, (double)((float)(j + i1) + 0.5F), this.a.yaw, this.a.pitch); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return; + } + } + } + } + } + + } + + protected boolean a(BlockPosition blockposition) { + IBlockData iblockdata = this.b.getType(blockposition); + return iblockdata.a(this.b, blockposition, this.a.getEntityType()) && this.b.isEmpty(blockposition.up()) && this.b.isEmpty(blockposition.up(2)); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index ac085f7..ad6f828 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -1,46 +1,46 @@ -package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; - -import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; -import net.minecraft.server.v1_14_R1.EntityLiving; -import net.minecraft.server.v1_14_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_14_R1.PathfinderTargetCondition; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.getLastDamager(); - int i = entityliving.ct(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.ct(); - } - - super.c(); - } -} +package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; + +import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; +import net.minecraft.server.v1_14_R1.EntityLiving; +import net.minecraft.server.v1_14_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_14_R1.PathfinderTargetCondition; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.ct(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.ct(); + } + + super.c(); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index d88a032..68516fd 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,47 +1,47 @@ -package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; - -import net.minecraft.server.v1_14_R1.EntityLiving; -import net.minecraft.server.v1_14_R1.EntityTameableAnimal; -import net.minecraft.server.v1_14_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_14_R1.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.cu(); - int i = entityliving.cv(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.cv(); - } - - super.c(); - } +package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; + +import net.minecraft.server.v1_14_R1.EntityLiving; +import net.minecraft.server.v1_14_R1.EntityTameableAnimal; +import net.minecraft.server.v1_14_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_14_R1.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.cu(); + int i = entityliving.cv(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.cv(); + } + + super.c(); + } } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalPanic.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalPanic.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalPanic.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalPanic.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSit.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSit.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSit.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSit.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java index 02c3150..f2f967a 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_14_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -1,130 +1,130 @@ -package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; - -import net.minecraft.server.v1_14_R1.*; -import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; - -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityHuman b; - private BlockPosition c; - private int d; - - public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { - this.a = tamableFox; - } - - public boolean a() { - if (!this.a.isTamed()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving instanceof EntityHuman) { - this.b = (EntityHuman)entityliving; - if (!entityliving.isSleeping()) { - return false; - } - - if (this.a.h(this.b) > 100.0D) { - return false; - } - - BlockPosition blockposition = new BlockPosition(this.b); - IBlockData iblockdata = this.a.world.getType(blockposition); - if (iblockdata.getBlock().a(TagsBlock.BEDS)) { - EnumDirection enumdirection = (EnumDirection)iblockdata.get(BlockBed.FACING); - this.c = new BlockPosition(blockposition.getX() - enumdirection.getAdjacentX(), blockposition.getY(), blockposition.getZ() - enumdirection.getAdjacentZ()); - return !this.g(); - } - } - - return false; - } - } - - private boolean g() { - List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); - Iterator iterator = list.iterator(); - - EntityTamableFox entityTamableFox; - do { - do { - if (!iterator.hasNext()) { - return false; - } - - entityTamableFox = (EntityTamableFox) iterator.next(); - } while(entityTamableFox == this.a); - } while(!entityTamableFox.eg()); // && !entityTamableFox.eh() <- isRelaxStateOne() - - return true; - } - - public boolean b() { - return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); - } - - public void c() { - if (this.c != null) { - this.a.getGoalSit().setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - } - - } - - public void d() { - this.a.setSleeping(false); - float f = this.a.world.j(1.0F); - if (this.b.dJ() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { - this.h(); - } - - this.d = 0; - //this.a.v(false); < setRelaxStateOne - this.a.getNavigation().o(); - } - - private void h() { - Random random = this.a.getRandom(); - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - blockposition_mutableblockposition.a(this.a); - this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); - blockposition_mutableblockposition.a(this.a); - LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.af); - LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); - List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); - Iterator iterator = list.iterator(); - - while(iterator.hasNext()) { - ItemStack itemstack = (ItemStack)iterator.next(); - this.a.world.addEntity(new EntityItem(this.a.world, (double)((float)blockposition_mutableblockposition.getX() - MathHelper.sin(this.a.aK * 0.017453292F)), (double)blockposition_mutableblockposition.getY(), (double)((float)blockposition_mutableblockposition.getZ() + MathHelper.cos(this.a.aK * 0.017453292F)), itemstack)); - } - - } - - public void e() { - if (this.b != null && this.c != null) { - this.a.getGoalSit().setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - if (this.a.h(this.b) < 2.5D) { - ++this.d; - if (this.d > 16) { - this.a.setSleeping(true); - //this.a.v(false); < setRelaxStateOne - } else { - this.a.a(this.b, 45.0F, 45.0F); - //this.a.v(true); < setRelaxStateOne - } - } else { - this.a.setSleeping(false); - } - } - - } -} +package net.seanomik.tamablefoxes.versions.version_1_14_R1.pathfinding; + +import net.minecraft.server.v1_14_R1.*; +import net.seanomik.tamablefoxes.TamableFoxes; +import net.seanomik.tamablefoxes.versions.version_1_14_R1.EntityTamableFox; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { + this.a = tamableFox; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman)entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.h(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = new BlockPosition(this.b); + IBlockData iblockdata = this.a.world.getType(blockposition); + if (iblockdata.getBlock().a(TagsBlock.BEDS)) { + EnumDirection enumdirection = (EnumDirection)iblockdata.get(BlockBed.FACING); + this.c = new BlockPosition(blockposition.getX() - enumdirection.getAdjacentX(), blockposition.getY(), blockposition.getZ() - enumdirection.getAdjacentZ()); + return !this.g(); + } + } + + return false; + } + } + + private boolean g() { + List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entityTamableFox; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entityTamableFox = (EntityTamableFox) iterator.next(); + } while(entityTamableFox == this.a); + } while(!entityTamableFox.eg()); // && !entityTamableFox.eh() <- isRelaxStateOne() + + return true; + } + + public boolean b() { + return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.getGoalSit().setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.world.j(1.0F); + if (this.b.dJ() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.v(false); < setRelaxStateOne + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.a(this.a); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.a(this.a); + LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.af); + LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + this.a.world.addEntity(new EntityItem(this.a.world, (double)((float)blockposition_mutableblockposition.getX() - MathHelper.sin(this.a.aK * 0.017453292F)), (double)blockposition_mutableblockposition.getY(), (double)((float)blockposition_mutableblockposition.getZ() + MathHelper.cos(this.a.aK * 0.017453292F)), itemstack)); + } + + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.getGoalSit().setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.h(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.v(false); < setRelaxStateOne + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.v(true); < setRelaxStateOne + } + } else { + this.a.setSleeping(false); + } + } + + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java similarity index 98% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java index da33406..72daa98 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/EntityTamableFox.java @@ -2,10 +2,10 @@ package net.seanomik.tamablefoxes.versions.version_1_15_R1; import net.minecraft.server.v1_15_R1.*; import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding.*; import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.Bukkit; @@ -318,7 +318,7 @@ public class EntityTamableFox extends EntityFox { itemstack.subtract(1); } - SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); int maxTameCount = Config.getMaxPlayerFoxTames(); if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); @@ -499,7 +499,7 @@ public class EntityTamableFox extends EntityFox { // Remove the amount of foxes the player has tamed if the limit is enabled. if (Config.getMaxPlayerFoxTames() > 0) { - SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java similarity index 83% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java index d1767fc..f3402f9 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/NMSInterface_1_15_R1.java @@ -1,36 +1,35 @@ -package net.seanomik.tamablefoxes.versions.version_1_15_R1; - -import net.minecraft.server.v1_15_R1.EntityFox; -import net.minecraft.server.v1_15_R1.EntityTypes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.versions.FieldHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.entity.EntityType; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class NMSInterface_1_15_R1 implements NMSInterface { - @Override - public void registerCustomFoxEntity() { - try { // Replace the fox entity - Field field = EntityTypes.FOX.getClass().getDeclaredField("ba"); - FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); - } catch (Exception e) { - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); - e.printStackTrace(); - } - } - - @Override - public void spawnTamableFox(Location loc, FoxType type) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); - tamableFox.setFoxType( (type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW ); - } -} +package net.seanomik.tamablefoxes.versions.version_1_15_R1; + +import net.minecraft.server.v1_15_R1.EntityFox; +import net.minecraft.server.v1_15_R1.EntityTypes; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; + +public class NMSInterface_1_15_R1 implements NMSInterface { + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.FOX.getClass().getDeclaredField("ba"); + FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType( (type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW ); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index 2530c8b..4442de5 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -1,139 +1,139 @@ -package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; - -import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.event.entity.EntityTeleportEvent; - -import java.util.EnumSet; - -public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityLiving b; - private final IWorldReader c; - private final double d; - private final NavigationAbstract e; - private int f; - private final float g; - private final float h; - private float i; - private final boolean j; - - public FoxPathfinderGoalFollowOwner(EntityTamableFox entityTamableFox, double d0, float f, float f1, boolean flag) { - this.a = entityTamableFox; - this.c = entityTamableFox.world; - this.d = d0; - this.e = entityTamableFox.getNavigation(); - this.h = f; - this.g = f1; - this.j = flag; - this.a(EnumSet.of(Type.MOVE, Type.LOOK)); - if (!(entityTamableFox.getNavigation() instanceof Navigation) && !(entityTamableFox.getNavigation() instanceof NavigationFlying)) { - throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); - } - } - - public boolean a() { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else if (entityliving.isSpectator()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { - return false; - } else { - this.b = entityliving; - return true; - } - } - - public boolean b() { - return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); - } - - public void c() { - this.f = 0; - this.i = this.a.a(PathType.WATER); - this.a.a(PathType.WATER, 0.0F); - } - - public void d() { - this.b = null; - this.e.o(); - this.a.a(PathType.WATER, this.i); - } - - public void e() { - this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.dU()); - if (--this.f <= 0) { - this.f = 10; - if (!this.a.isLeashed() && !this.a.isPassenger()) { - if (this.a.h(this.b) >= 144.0D) { - this.g(); - } else { - this.e.a(this.b, this.d); - } - } - } - - } - - private void g() { - BlockPosition blockposition = new BlockPosition(this.b); - - for(int i = 0; i < 10; ++i) { - int j = this.a(-3, 3); - int k = this.a(-1, 1); - int l = this.a(-3, 3); - boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); - if (flag) { - return; - } - } - - } - - private boolean a(int i, int j, int k) { - if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { - return false; - } else if (!this.a(new BlockPosition(i, j, k))) { - return false; - } else { - CraftEntity entity = this.a.getBukkitEntity(); - Location to = new Location(entity.getWorld(), (double)((float)i + 0.5F), (double)j, (double)((float)k + 0.5F), this.a.yaw, this.a.pitch); - EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); - this.a.world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return false; - } else { - to = event.getTo(); - this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - this.e.o(); - return true; - } - } - } - - private boolean a(BlockPosition blockposition) { - PathType pathtype = PathfinderNormal.b(this.c, blockposition.getX(), blockposition.getY(), blockposition.getZ()); - if (pathtype != PathType.WALKABLE) { - return false; - } else { - IBlockData iblockdata = this.c.getType(blockposition.down()); - if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { - return false; - } else { - BlockPosition blockposition1 = blockposition.b(new BlockPosition(this.a)); - return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); - } - } - } - - private int a(int i, int j) { - return this.a.getRandom().nextInt(j - i + 1) + i; - } - -} +package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; + +import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; +import net.minecraft.server.v1_15_R1.*; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityLiving b; + private final IWorldReader c; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + private final boolean j; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox entityTamableFox, double d0, float f, float f1, boolean flag) { + this.a = entityTamableFox; + this.c = entityTamableFox.world; + this.d = d0; + this.e = entityTamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.j = flag; + this.a(EnumSet.of(Type.MOVE, Type.LOOK)); + if (!(entityTamableFox.getNavigation() instanceof Navigation) && !(entityTamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving.isSpectator()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.b = entityliving; + return true; + } + } + + public boolean b() { + return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.WATER); + this.a.a(PathType.WATER, 0.0F); + } + + public void d() { + this.b = null; + this.e.o(); + this.a.a(PathType.WATER, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.dU()); + if (--this.f <= 0) { + this.f = 10; + if (!this.a.isLeashed() && !this.a.isPassenger()) { + if (this.a.h(this.b) >= 144.0D) { + this.g(); + } else { + this.e.a(this.b, this.d); + } + } + } + + } + + private void g() { + BlockPosition blockposition = new BlockPosition(this.b); + + for(int i = 0; i < 10; ++i) { + int j = this.a(-3, 3); + int k = this.a(-1, 1); + int l = this.a(-3, 3); + boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); + if (flag) { + return; + } + } + + } + + private boolean a(int i, int j, int k) { + if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { + return false; + } else if (!this.a(new BlockPosition(i, j, k))) { + return false; + } else { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)((float)i + 0.5F), (double)j, (double)((float)k + 0.5F), this.a.yaw, this.a.pitch); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } else { + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return true; + } + } + } + + private boolean a(BlockPosition blockposition) { + PathType pathtype = PathfinderNormal.b(this.c, blockposition.getX(), blockposition.getY(), blockposition.getZ()); + if (pathtype != PathType.WALKABLE) { + return false; + } else { + IBlockData iblockdata = this.c.getType(blockposition.down()); + if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { + return false; + } else { + BlockPosition blockposition1 = blockposition.b(new BlockPosition(this.a)); + return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); + } + } + } + + private int a(int i, int j) { + return this.a.getRandom().nextInt(j - i + 1) + i; + } + +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index 880a7e1..f2ed07b 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -1,48 +1,48 @@ -package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; - -import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; -import net.minecraft.server.v1_15_R1.EntityLiving; -import net.minecraft.server.v1_15_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_15_R1.PathfinderTargetCondition; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { - - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.getLastDamager(); - int i = entityliving.cI(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.cI(); - } - - super.c(); - } - -} +package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; + +import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; +import net.minecraft.server.v1_15_R1.EntityLiving; +import net.minecraft.server.v1_15_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_15_R1.PathfinderTargetCondition; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.cI(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.cI(); + } + + super.c(); + } + +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index b5e3350..5d6dd12 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,47 +1,47 @@ -package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; - -import net.minecraft.server.v1_15_R1.EntityLiving; -import net.minecraft.server.v1_15_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_15_R1.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { - private final EntityTamableFox fox; - private EntityLiving hitEntity; - private int c; - - public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox entityTamableFox) { - super(entityTamableFox, false); - this.fox = entityTamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (fox.isTamed() && !fox.isSitting()) { - EntityLiving entityliving = fox.getOwner(); - if (entityliving == null) { - e.setGoalTarget(null); - return false; - } else { - hitEntity = entityliving.cJ(); - int i = entityliving.cK(); - return i != this.c && this.a(hitEntity, PathfinderTargetCondition.a) && fox.a(hitEntity, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(hitEntity, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = fox.getOwner(); - if (entityliving != null) { - this.c = entityliving.cK(); - } - - super.c(); - } +package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; + +import net.minecraft.server.v1_15_R1.EntityLiving; +import net.minecraft.server.v1_15_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_15_R1.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox fox; + private EntityLiving hitEntity; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox entityTamableFox) { + super(entityTamableFox, false); + this.fox = entityTamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (fox.isTamed() && !fox.isSitting()) { + EntityLiving entityliving = fox.getOwner(); + if (entityliving == null) { + e.setGoalTarget(null); + return false; + } else { + hitEntity = entityliving.cJ(); + int i = entityliving.cK(); + return i != this.c && this.a(hitEntity, PathfinderTargetCondition.a) && fox.a(hitEntity, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(hitEntity, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = fox.getOwner(); + if (entityliving != null) { + this.c = entityliving.cK(); + } + + super.c(); + } } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalPanic.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalPanic.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalPanic.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalPanic.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSit.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSit.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSit.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSit.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java index 7573f3f..8bdd4a5 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_15_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -1,130 +1,130 @@ -package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; - -import net.minecraft.server.v1_15_R1.*; -import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; - -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityHuman b; - private BlockPosition c; - private int d; - - public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { - this.a = tamableFox; - } - - public boolean a() { - if (!this.a.isTamed()) { - return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() - return false; - } else { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving instanceof EntityHuman) { - this.b = (EntityHuman)entityliving; - if (!entityliving.isSleeping()) { - return false; - } - - if (this.a.h(this.b) > 100.0D) { - return false; - } - - BlockPosition blockposition = new BlockPosition(this.b); - IBlockData iblockdata = this.a.world.getType(blockposition); - if (iblockdata.getBlock().a(TagsBlock.BEDS)) { - EnumDirection enumdirection = (EnumDirection)iblockdata.get(BlockBed.FACING); - this.c = new BlockPosition(blockposition.getX() - enumdirection.getAdjacentX(), blockposition.getY(), blockposition.getZ() - enumdirection.getAdjacentZ()); - return !this.g(); - } - } - - return false; - } - } - - private boolean g() { - List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); - Iterator iterator = list.iterator(); - - EntityTamableFox entityTamableFox; - do { - do { - if (!iterator.hasNext()) { - return false; - } - - entityTamableFox = (EntityTamableFox) iterator.next(); - } while(entityTamableFox == this.a); - } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() - - return true; - } - - public boolean b() { - //!this.a.isWillSit() - return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); - } - - public void c() { - if (this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - } - - } - - public void d() { - this.a.setSleeping(false); - float f = this.a.world.f(1.0F); - if (this.b.ef() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { - this.h(); - } - - this.d = 0; - //this.a.v(false); // setRelaxStateOne - this.a.getNavigation().o(); - } - - private void h() { - Random random = this.a.getRandom(); - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); - LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); - List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); - Iterator iterator = list.iterator(); - - while(iterator.hasNext()) { - ItemStack itemstack = (ItemStack)iterator.next(); - this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aH * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aH * 0.017453292F), itemstack)); - } - - } - - public void e() { - if (this.b != null && this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - if (this.a.h(this.b) < 2.5D) { - ++this.d; - if (this.d > 16) { - this.a.setSleeping(true); - //this.a.y(false); // setRelaxStateOne - } else { - this.a.a(this.b, 45.0F, 45.0F); - //this.a.y(true); // setRelaxStateOne - } - } else { - this.a.setSleeping(false); - //this.a.x(false); - } - } - } -} +package net.seanomik.tamablefoxes.versions.version_1_15_R1.pathfinding; + +import net.minecraft.server.v1_15_R1.*; +import net.seanomik.tamablefoxes.versions.version_1_15_R1.EntityTamableFox; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { + this.a = tamableFox; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { // this.a.isWillSit() + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman)entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.h(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = new BlockPosition(this.b); + IBlockData iblockdata = this.a.world.getType(blockposition); + if (iblockdata.getBlock().a(TagsBlock.BEDS)) { + EnumDirection enumdirection = (EnumDirection)iblockdata.get(BlockBed.FACING); + this.c = new BlockPosition(blockposition.getX() - enumdirection.getAdjacentX(), blockposition.getY(), blockposition.getZ() - enumdirection.getAdjacentZ()); + return !this.g(); + } + } + + return false; + } + } + + private boolean g() { + List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entityTamableFox; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entityTamableFox = (EntityTamableFox) iterator.next(); + } while(entityTamableFox == this.a); + } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() + + return true; + } + + public boolean b() { + //!this.a.isWillSit() + return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.world.f(1.0F); + if (this.b.ef() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.v(false); // setRelaxStateOne + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); + LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aH * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aH * 0.017453292F), itemstack)); + } + + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.h(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.y(false); // setRelaxStateOne + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.y(true); // setRelaxStateOne + } + } else { + this.a.setSleeping(false); + //this.a.x(false); + } + } + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java similarity index 98% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java index 08c17b8..f896d62 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/EntityTamableFox.java @@ -2,10 +2,10 @@ package net.seanomik.tamablefoxes.versions.version_1_16_R1; import net.minecraft.server.v1_16_R1.*; import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding.*; import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.Bukkit; @@ -321,7 +321,7 @@ public class EntityTamableFox extends EntityFox { itemstack.subtract(1); } - SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); int maxTameCount = Config.getMaxPlayerFoxTames(); if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); @@ -503,7 +503,7 @@ public class EntityTamableFox extends EntityFox { // Remove the amount of foxes the player has tamed if the limit is enabled. if (Config.getMaxPlayerFoxTames() > 0) { - SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java similarity index 83% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java index 35e877e..a98e311 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/NMSInterface_1_16_R1.java @@ -1,37 +1,36 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R1; - -import net.minecraft.server.v1_16_R1.EntityTypes; -import net.minecraft.server.v1_16_R1.EntityFox; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.versions.FieldHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.entity.EntityType; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -public class NMSInterface_1_16_R1 implements NMSInterface { - - @Override - public void registerCustomFoxEntity() { - try { // Replace the fox entity - Field field = EntityTypes.FOX.getClass().getDeclaredField("be"); - FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); - } catch (Exception e) { - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); - e.printStackTrace(); - } - } - - @Override - public void spawnTamableFox(Location loc, FoxType type) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); - tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R1; + +import net.minecraft.server.v1_16_R1.EntityTypes; +import net.minecraft.server.v1_16_R1.EntityFox; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; + +public class NMSInterface_1_16_R1 implements NMSInterface { + + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.FOX.getClass().getDeclaredField("be"); + FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java index f391d13..c7ebd64 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -1,139 +1,139 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; - -import net.minecraft.server.v1_16_R1.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; -import org.bukkit.event.entity.EntityTeleportEvent; - -import java.util.EnumSet; - -public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityLiving b; - private final IWorldReader c; - private final double d; - private final NavigationAbstract e; - private int f; - private final float g; - private final float h; - private float i; - private final boolean j; - - public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { - this.a = tamableFox; - this.c = tamableFox.world; - this.d = d0; - this.e = tamableFox.getNavigation(); - this.h = f; - this.g = f1; - this.j = flag; - this.a(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK)); - if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { - throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); - } - } - - public boolean a() { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else if (entityliving.isSpectator()) { - return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() - return false; - } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { - return false; - } else { - this.b = entityliving; - return true; - } - } - - public boolean b() { - // !this.a.isWillSit() - return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); - } - - public void c() { - this.f = 0; - this.i = this.a.a(PathType.WATER); - this.a.a(PathType.WATER, 0.0F); - } - - public void d() { - this.b = null; - this.e.o(); - this.a.a(PathType.WATER, this.i); - } - - public void e() { - this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.eo()); - if (--this.f <= 0) { - this.f = 10; - if (!this.a.isLeashed() && !this.a.isPassenger()) { - if (this.a.h(this.b) >= 144.0D) { - this.g(); - } else { - this.e.a(this.b, this.d); - } - } - } - - } - - private void g() { - BlockPosition blockposition = this.b.getChunkCoordinates(); - - for(int i = 0; i < 10; ++i) { - int j = this.a(-3, 3); - int k = this.a(-1, 1); - int l = this.a(-3, 3); - boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); - if (flag) { - return; - } - } - - } - - private boolean a(int i, int j, int k) { - if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { - return false; - } else if (!this.a(new BlockPosition(i, j, k))) { - return false; - } else { - CraftEntity entity = this.a.getBukkitEntity(); - Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); - EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); - this.a.world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return false; - } else { - to = event.getTo(); - this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - this.e.o(); - return true; - } - } - } - - private boolean a(BlockPosition blockposition) { - PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); - if (pathtype != PathType.WALKABLE) { - return false; - } else { - IBlockData iblockdata = this.c.getType(blockposition.down()); - if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { - return false; - } else { - BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); - return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); - } - } - } - - private int a(int i, int j) { - return this.a.getRandom().nextInt(j - i + 1) + i; - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; + +import net.minecraft.server.v1_16_R1.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityLiving b; + private final IWorldReader c; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + private final boolean j; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { + this.a = tamableFox; + this.c = tamableFox.world; + this.d = d0; + this.e = tamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.j = flag; + this.a(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK)); + if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving.isSpectator()) { + return false; + } else if (this.a.isSitting()) { // this.a.isWillSit() + return false; + } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.b = entityliving; + return true; + } + } + + public boolean b() { + // !this.a.isWillSit() + return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.WATER); + this.a.a(PathType.WATER, 0.0F); + } + + public void d() { + this.b = null; + this.e.o(); + this.a.a(PathType.WATER, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.eo()); + if (--this.f <= 0) { + this.f = 10; + if (!this.a.isLeashed() && !this.a.isPassenger()) { + if (this.a.h(this.b) >= 144.0D) { + this.g(); + } else { + this.e.a(this.b, this.d); + } + } + } + + } + + private void g() { + BlockPosition blockposition = this.b.getChunkCoordinates(); + + for(int i = 0; i < 10; ++i) { + int j = this.a(-3, 3); + int k = this.a(-1, 1); + int l = this.a(-3, 3); + boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); + if (flag) { + return; + } + } + + } + + private boolean a(int i, int j, int k) { + if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { + return false; + } else if (!this.a(new BlockPosition(i, j, k))) { + return false; + } else { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } else { + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return true; + } + } + } + + private boolean a(BlockPosition blockposition) { + PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); + if (pathtype != PathType.WALKABLE) { + return false; + } else { + IBlockData iblockdata = this.c.getType(blockposition.down()); + if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { + return false; + } else { + BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); + return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); + } + } + } + + private int a(int i, int j) { + return this.a.getRandom().nextInt(j - i + 1) + i; + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalHurtByTarget.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index 5964014..b3f2e5b 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -1,47 +1,47 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; - -import net.minecraft.server.v1_16_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R1.EntityLiving; -import net.minecraft.server.v1_16_R1.PathfinderGoal; -import net.minecraft.server.v1_16_R1.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private net.minecraft.server.v1_16_R1.EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(PathfinderGoal.Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.getLastDamager(); - int i = entityliving.cZ(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.cZ(); - } - - super.c(); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; + +import net.minecraft.server.v1_16_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R1.EntityLiving; +import net.minecraft.server.v1_16_R1.PathfinderGoal; +import net.minecraft.server.v1_16_R1.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private net.minecraft.server.v1_16_R1.EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(PathfinderGoal.Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.cZ(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.cZ(); + } + + super.c(); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index 7ef963d..a04f264 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,48 +1,48 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; - -import net.minecraft.server.v1_16_R1.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R1.EntityLiving; -import net.minecraft.server.v1_16_R1.EntityTameableAnimal; -import net.minecraft.server.v1_16_R1.PathfinderGoal; -import net.minecraft.server.v1_16_R1.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private net.minecraft.server.v1_16_R1.EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(PathfinderGoal.Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() - net.minecraft.server.v1_16_R1.EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.da(); - int i = entityliving.db(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.db(); - } - - super.c(); - } +package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; + +import net.minecraft.server.v1_16_R1.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R1.EntityLiving; +import net.minecraft.server.v1_16_R1.EntityTameableAnimal; +import net.minecraft.server.v1_16_R1.PathfinderGoal; +import net.minecraft.server.v1_16_R1.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private net.minecraft.server.v1_16_R1.EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(PathfinderGoal.Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() + net.minecraft.server.v1_16_R1.EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.da(); + int i = entityliving.db(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.db(); + } + + super.c(); + } } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalPanic.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalPanic.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalPanic.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalPanic.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSit.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSit.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSit.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSit.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java index 6d81401..b9941c9 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R1/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -1,134 +1,134 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; - -import net.minecraft.server.v1_16_R1.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; - -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityHuman b; - private BlockPosition c; - private int d; - - public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { - this.a = tamableFox; - } - - public boolean a() { - if (!this.a.isTamed()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving instanceof EntityHuman) { - this.b = (EntityHuman)entityliving; - if (!entityliving.isSleeping()) { - return false; - } - - if (this.a.h(this.b) > 100.0D) { - return false; - } - - BlockPosition blockposition = this.b.getChunkCoordinates(); - IBlockData iblockdata = this.a.world.getType(blockposition); - if (iblockdata.getBlock().a(TagsBlock.BEDS)) { - this.c = (BlockPosition)iblockdata.d(BlockBed.FACING).map((enumdirection) -> { - return blockposition.shift(enumdirection.opposite()); - }).orElseGet(() -> { - return new BlockPosition(blockposition); - }); - return !this.g(); - } - } - - return false; - } - } - - private boolean g() { - List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); - Iterator iterator = list.iterator(); - - EntityTamableFox entityTamableFox; - do { - do { - if (!iterator.hasNext()) { - return false; - } - - entityTamableFox = (EntityTamableFox) iterator.next(); - } while(entityTamableFox == this.a); - } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() - - return true; - } - - public boolean b() { - //!this.a.isWillSit() - return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); - } - - public void c() { - if (this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - } - - } - - public void d() { - this.a.setSleeping(false); - float f = this.a.world.f(1.0F); - if (this.b.eB() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { - this.h(); - } - - this.d = 0; - //this.a.y(false); // setRelaxStateOne - this.a.getNavigation().o(); - } - - private void h() { - Random random = this.a.getRandom(); - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); - net.minecraft.server.v1_16_R1.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R1.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); - List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); - Iterator iterator = list.iterator(); - - while(iterator.hasNext()) { - ItemStack itemstack = (ItemStack)iterator.next(); - this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aH * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aH * 0.017453292F), itemstack)); - } - - } - - public void e() { - if (this.b != null && this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - if (this.a.h(this.b) < 2.5D) { - ++this.d; - if (this.d > 16) { - this.a.setSleeping(true); - //this.a.y(false); // setRelaxStateOne - } else { - this.a.a(this.b, 45.0F, 45.0F); - //this.a.y(true); // setRelaxStateOne - } - } else { - this.a.setSleeping(false); - //this.a.x(false); - } - } - - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R1.pathfinding; + +import net.minecraft.server.v1_16_R1.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R1.EntityTamableFox; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { + this.a = tamableFox; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman)entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.h(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = this.b.getChunkCoordinates(); + IBlockData iblockdata = this.a.world.getType(blockposition); + if (iblockdata.getBlock().a(TagsBlock.BEDS)) { + this.c = (BlockPosition)iblockdata.d(BlockBed.FACING).map((enumdirection) -> { + return blockposition.shift(enumdirection.opposite()); + }).orElseGet(() -> { + return new BlockPosition(blockposition); + }); + return !this.g(); + } + } + + return false; + } + } + + private boolean g() { + List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entityTamableFox; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entityTamableFox = (EntityTamableFox) iterator.next(); + } while(entityTamableFox == this.a); + } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() + + return true; + } + + public boolean b() { + //!this.a.isWillSit() + return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.world.f(1.0F); + if (this.b.eB() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.y(false); // setRelaxStateOne + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); + net.minecraft.server.v1_16_R1.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R1.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.POSITION, blockposition_mutableblockposition).set(LootContextParameters.THIS_ENTITY, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aH * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aH * 0.017453292F), itemstack)); + } + + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.h(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.y(false); // setRelaxStateOne + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.y(true); // setRelaxStateOne + } + } else { + this.a.setSleeping(false); + //this.a.x(false); + } + } + + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java similarity index 98% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java index 474e1f9..83678fc 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/EntityTamableFox.java @@ -2,10 +2,10 @@ package net.seanomik.tamablefoxes.versions.version_1_16_R2; import net.minecraft.server.v1_16_R2.*; import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding.*; import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.Bukkit; @@ -318,7 +318,7 @@ public class EntityTamableFox extends EntityFox { itemstack.subtract(1); } - SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); int maxTameCount = Config.getMaxPlayerFoxTames(); if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); @@ -500,7 +500,7 @@ public class EntityTamableFox extends EntityFox { // Remove the amount of foxes the player has tamed if the limit is enabled. if (Config.getMaxPlayerFoxTames() > 0) { - SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java similarity index 85% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java index b3bea78..5c5b086 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/NMSInterface_1_16_R2.java @@ -1,36 +1,36 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R2; - -import net.minecraft.server.v1_16_R2.EntityFox; -import net.minecraft.server.v1_16_R2.EntityTypes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.versions.FieldHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.entity.EntityType; - -import java.lang.reflect.Field; - -public class NMSInterface_1_16_R2 implements NMSInterface { - - @Override - public void registerCustomFoxEntity() { - try { // Replace the fox entity - Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); - FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); - } catch (Exception e) { - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); - e.printStackTrace(); - } - } - - @Override - public void spawnTamableFox(Location loc, FoxType type) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); - tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R2; + +import net.minecraft.server.v1_16_R2.EntityFox; +import net.minecraft.server.v1_16_R2.EntityTypes; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; + +public class NMSInterface_1_16_R2 implements NMSInterface { + + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); + FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java index 9fb7253..d80f3a0 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -1,139 +1,139 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; - -import net.minecraft.server.v1_16_R2.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; -import org.bukkit.event.entity.EntityTeleportEvent; - -import java.util.EnumSet; - -public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityLiving b; - private final IWorldReader c; - private final double d; - private final NavigationAbstract e; - private int f; - private final float g; - private final float h; - private float i; - private final boolean j; - - public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { - this.a = tamableFox; - this.c = tamableFox.world; - this.d = d0; - this.e = tamableFox.getNavigation(); - this.h = f; - this.g = f1; - this.j = flag; - this.a(EnumSet.of(Type.MOVE, Type.LOOK)); - if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { - throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); - } - } - - public boolean a() { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else if (entityliving.isSpectator()) { - return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() - return false; - } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { - return false; - } else { - this.b = entityliving; - return true; - } - } - - public boolean b() { - // !this.a.isWillSit() - return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); - } - - public void c() { - this.f = 0; - this.i = this.a.a(PathType.WATER); - this.a.a(PathType.WATER, 0.0F); - } - - public void d() { - this.b = null; - this.e.o(); - this.a.a(PathType.WATER, this.i); - } - - public void e() { - this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.eo()); - if (--this.f <= 0) { - this.f = 10; - if (!this.a.isLeashed() && !this.a.isPassenger()) { - if (this.a.h(this.b) >= 144.0D) { - this.g(); - } else { - this.e.a(this.b, this.d); - } - } - } - - } - - private void g() { - BlockPosition blockposition = this.b.getChunkCoordinates(); - - for(int i = 0; i < 10; ++i) { - int j = this.a(-3, 3); - int k = this.a(-1, 1); - int l = this.a(-3, 3); - boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); - if (flag) { - return; - } - } - - } - - private boolean a(int i, int j, int k) { - if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { - return false; - } else if (!this.a(new BlockPosition(i, j, k))) { - return false; - } else { - CraftEntity entity = this.a.getBukkitEntity(); - Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); - EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); - this.a.world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return false; - } else { - to = event.getTo(); - this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - this.e.o(); - return true; - } - } - } - - private boolean a(BlockPosition blockposition) { - PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); - if (pathtype != PathType.WALKABLE) { - return false; - } else { - IBlockData iblockdata = this.c.getType(blockposition.down()); - if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { - return false; - } else { - BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); - return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); - } - } - } - - private int a(int i, int j) { - return this.a.getRandom().nextInt(j - i + 1) + i; - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; + +import net.minecraft.server.v1_16_R2.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityLiving b; + private final IWorldReader c; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + private final boolean j; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { + this.a = tamableFox; + this.c = tamableFox.world; + this.d = d0; + this.e = tamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.j = flag; + this.a(EnumSet.of(Type.MOVE, Type.LOOK)); + if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving.isSpectator()) { + return false; + } else if (this.a.isSitting()) { // this.a.isWillSit() + return false; + } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.b = entityliving; + return true; + } + } + + public boolean b() { + // !this.a.isWillSit() + return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.WATER); + this.a.a(PathType.WATER, 0.0F); + } + + public void d() { + this.b = null; + this.e.o(); + this.a.a(PathType.WATER, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.eo()); + if (--this.f <= 0) { + this.f = 10; + if (!this.a.isLeashed() && !this.a.isPassenger()) { + if (this.a.h(this.b) >= 144.0D) { + this.g(); + } else { + this.e.a(this.b, this.d); + } + } + } + + } + + private void g() { + BlockPosition blockposition = this.b.getChunkCoordinates(); + + for(int i = 0; i < 10; ++i) { + int j = this.a(-3, 3); + int k = this.a(-1, 1); + int l = this.a(-3, 3); + boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); + if (flag) { + return; + } + } + + } + + private boolean a(int i, int j, int k) { + if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { + return false; + } else if (!this.a(new BlockPosition(i, j, k))) { + return false; + } else { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } else { + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return true; + } + } + } + + private boolean a(BlockPosition blockposition) { + PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); + if (pathtype != PathType.WALKABLE) { + return false; + } else { + IBlockData iblockdata = this.c.getType(blockposition.down()); + if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { + return false; + } else { + BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); + return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); + } + } + } + + private int a(int i, int j) { + return this.a.getRandom().nextInt(j - i + 1) + i; + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalHurtByTarget.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalHurtByTarget.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index 4b36131..9f12d23 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -1,46 +1,46 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; - -import net.minecraft.server.v1_16_R2.EntityLiving; -import net.minecraft.server.v1_16_R2.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R2.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.getLastDamager(); - int i = entityliving.cZ(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.cZ(); - } - - super.c(); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; + +import net.minecraft.server.v1_16_R2.EntityLiving; +import net.minecraft.server.v1_16_R2.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R2.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.cZ(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.cZ(); + } + + super.c(); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index 3e5261f..1ce00c0 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,46 +1,46 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; - -import net.minecraft.server.v1_16_R2.EntityLiving; -import net.minecraft.server.v1_16_R2.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R2.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.da(); - int i = entityliving.db(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.db(); - } - - super.c(); - } +package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; + +import net.minecraft.server.v1_16_R2.EntityLiving; +import net.minecraft.server.v1_16_R2.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R2.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.da(); + int i = entityliving.db(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.db(); + } + + super.c(); + } } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalPanic.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalPanic.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalPanic.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalPanic.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSit.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSit.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSit.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSit.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java index b7e7477..579e5ba 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R2/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -1,133 +1,133 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; - -import net.minecraft.server.v1_16_R2.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; - -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityHuman b; - private BlockPosition c; - private int d; - - public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { - this.a = tamableFox; - } - - public boolean a() { - if (!this.a.isTamed()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving instanceof EntityHuman) { - this.b = (EntityHuman)entityliving; - if (!entityliving.isSleeping()) { - return false; - } - - if (this.a.h(this.b) > 100.0D) { - return false; - } - - BlockPosition blockposition = this.b.getChunkCoordinates(); - IBlockData iblockdata = this.a.world.getType(blockposition); - if (iblockdata.getBlock().a(TagsBlock.BEDS)) { - this.c = (BlockPosition)iblockdata.d(BlockBed.FACING).map((enumdirection) -> { - return blockposition.shift(enumdirection.opposite()); - }).orElseGet(() -> { - return new BlockPosition(blockposition); - }); - return !this.g(); - } - } - - return false; - } - } - - private boolean g() { - List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); - Iterator iterator = list.iterator(); - - EntityTamableFox entityTamableFox; - do { - do { - if (!iterator.hasNext()) { - return false; - } - - entityTamableFox = (EntityTamableFox) iterator.next(); - } while(entityTamableFox == this.a); - } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() - - return true; - } - - public boolean b() { - //!this.a.isWillSit() - return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); - } - - public void c() { - if (this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - } - - } - - public void d() { - this.a.setSleeping(false); - float f = this.a.world.f(1.0F); - if (this.b.eB() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { - this.h(); - } - - this.d = 0; - //this.a.y(false); // setRelaxStateOne - this.a.getNavigation().o(); - } - - private void h() { - Random random = this.a.getRandom(); - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); - net.minecraft.server.v1_16_R2.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R2.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.ORIGIN, this.a.getPositionVector()).set(LootContextParameters.THIS_ENTITY, this.a).a(random); - List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); - Iterator iterator = list.iterator(); - - while(iterator.hasNext()) { - ItemStack itemstack = (ItemStack)iterator.next(); - this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aA * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aA * 0.017453292F), itemstack)); - } - } - - public void e() { - if (this.b != null && this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - if (this.a.h(this.b) < 2.5D) { - ++this.d; - if (this.d > 16) { - this.a.setSleeping(true); - //this.a.y(false); // setRelaxStateOne - } else { - this.a.a(this.b, 45.0F, 45.0F); - //this.a.y(true); // setRelaxStateOne - } - } else { - this.a.setSleeping(false); - //this.a.x(false); - } - } - - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R2.pathfinding; + +import net.minecraft.server.v1_16_R2.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R2.EntityTamableFox; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox tamableFox) { + this.a = tamableFox; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman)entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.h(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = this.b.getChunkCoordinates(); + IBlockData iblockdata = this.a.world.getType(blockposition); + if (iblockdata.getBlock().a(TagsBlock.BEDS)) { + this.c = (BlockPosition)iblockdata.d(BlockBed.FACING).map((enumdirection) -> { + return blockposition.shift(enumdirection.opposite()); + }).orElseGet(() -> { + return new BlockPosition(blockposition); + }); + return !this.g(); + } + } + + return false; + } + } + + private boolean g() { + List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entityTamableFox; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entityTamableFox = (EntityTamableFox) iterator.next(); + } while(entityTamableFox == this.a); + } while(!entityTamableFox.isSleeping()); // !entityTamableFox.eY() + + return true; + } + + public boolean b() { + //!this.a.isWillSit() + return this.a.isTamed() && !this.a.isSitting() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.world.f(1.0F); + if (this.b.eB() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.y(false); // setRelaxStateOne + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); + net.minecraft.server.v1_16_R2.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R2.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.ORIGIN, this.a.getPositionVector()).set(LootContextParameters.THIS_ENTITY, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aA * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aA * 0.017453292F), itemstack)); + } + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.h(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.y(false); // setRelaxStateOne + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.y(true); // setRelaxStateOne + } + } else { + this.a.setSleeping(false); + //this.a.x(false); + } + } + + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java similarity index 98% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java index ac82927..d398654 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/EntityTamableFox.java @@ -2,10 +2,10 @@ package net.seanomik.tamablefoxes.versions.version_1_16_R3; import net.minecraft.server.v1_16_R3.*; import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.Config; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.io.sqlite.SQLiteHelper; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.Config; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.sqlite.SQLiteHelper; import net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding.*; import net.wesjd.anvilgui.AnvilGUI; import org.bukkit.Bukkit; @@ -319,7 +319,7 @@ public class EntityTamableFox extends EntityFox { itemstack.subtract(1); } - SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqLiteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); int maxTameCount = Config.getMaxPlayerFoxTames(); if ( !((Player) entityhuman.getBukkitEntity()).hasPermission("tamablefoxes.tame.unlimited") && maxTameCount > 0 && sqLiteHelper.getPlayerFoxAmount(entityhuman.getUniqueID()) >= maxTameCount) { ((Player) entityhuman.getBukkitEntity()).sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFoxDoesntTrust()); @@ -501,7 +501,7 @@ public class EntityTamableFox extends EntityFox { // Remove the amount of foxes the player has tamed if the limit is enabled. if (Config.getMaxPlayerFoxTames() > 0) { - SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(); + SQLiteHelper sqliteHelper = SQLiteHelper.getInstance(TamableFoxes.getPlugin()); sqliteHelper.removePlayerFoxAmount(this.getOwner().getUniqueID(), 1); } } diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java similarity index 85% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java index db9d307..d76e8b7 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/NMSInterface_1_16_R3.java @@ -1,36 +1,36 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R3; - -import net.minecraft.server.v1_16_R3.EntityFox; -import net.minecraft.server.v1_16_R3.EntityTypes; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; -import net.seanomik.tamablefoxes.versions.FieldHelper; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.entity.EntityType; - -import java.lang.reflect.Field; - -public class NMSInterface_1_16_R3 implements NMSInterface { - - @Override - public void registerCustomFoxEntity() { - try { // Replace the fox entity - Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); - FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); - } catch (Exception e) { - Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); - e.printStackTrace(); - } - } - - @Override - public void spawnTamableFox(Location loc, FoxType type) { - EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); - tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R3; + +import net.minecraft.server.v1_16_R3.EntityFox; +import net.minecraft.server.v1_16_R3.EntityTypes; +import net.seanomik.tamablefoxes.util.FieldHelper; +import net.seanomik.tamablefoxes.util.NMSInterface; +import net.seanomik.tamablefoxes.util.Utils; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; +import org.bukkit.entity.EntityType; + +import java.lang.reflect.Field; + +public class NMSInterface_1_16_R3 implements NMSInterface { + + @Override + public void registerCustomFoxEntity() { + try { // Replace the fox entity + Field field = EntityTypes.FOX.getClass().getDeclaredField("bf"); + FieldHelper.setField(field, EntityTypes.FOX, (EntityTypes.b) EntityTamableFox::new); + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.GREEN + LanguageConfig.getSuccessReplaced()); + } catch (Exception e) { + Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace()); + e.printStackTrace(); + } + } + + @Override + public void spawnTamableFox(Location loc, FoxType type) { + EntityTamableFox tamableFox = (EntityTamableFox) ((CraftEntity) loc.getWorld().spawnEntity(loc, EntityType.FOX)).getHandle(); + tamableFox.setFoxType((type == FoxType.RED) ? EntityFox.Type.RED : EntityFox.Type.SNOW); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java index 75adde4..1f11ea6 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalFollowOwner.java @@ -1,139 +1,139 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; - -import net.minecraft.server.v1_16_R3.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.event.entity.EntityTeleportEvent; - -import java.util.EnumSet; - -public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityLiving b; - private final IWorldReader c; - private final double d; - private final NavigationAbstract e; - private int f; - private final float g; - private final float h; - private float i; - private final boolean j; - - public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { - this.a = tamableFox; - this.c = tamableFox.world; - this.d = d0; - this.e = tamableFox.getNavigation(); - this.h = f; - this.g = f1; - this.j = flag; - this.a(EnumSet.of(Type.MOVE, Type.LOOK)); - if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { - throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); - } - } - - public boolean a() { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else if (entityliving.isSpectator()) { - return false; - } else if (this.a.isSitting()) { // this.a.isWillSit() - return false; - } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { - return false; - } else { - this.b = entityliving; - return true; - } - } - - public boolean b() { - // !this.a.isWillSit() - return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); - } - - public void c() { - this.f = 0; - this.i = this.a.a(PathType.WATER); - this.a.a(PathType.WATER, 0.0F); - } - - public void d() { - this.b = null; - this.e.o(); - this.a.a(PathType.WATER, this.i); - } - - public void e() { - this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.O()); - if (--this.f <= 0) { - this.f = 10; - if (!this.a.isLeashed() && !this.a.isPassenger()) { - if (this.a.h(this.b) >= 144.0D) { - this.g(); - } else { - this.e.a(this.b, this.d); - } - } - } - - } - - private void g() { - BlockPosition blockposition = this.b.getChunkCoordinates(); - - for(int i = 0; i < 10; ++i) { - int j = this.a(-3, 3); - int k = this.a(-1, 1); - int l = this.a(-3, 3); - boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); - if (flag) { - return; - } - } - - } - - private boolean a(int i, int j, int k) { - if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { - return false; - } else if (!this.a(new BlockPosition(i, j, k))) { - return false; - } else { - CraftEntity entity = this.a.getBukkitEntity(); - Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); - EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); - this.a.world.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return false; - } else { - to = event.getTo(); - this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); - this.e.o(); - return true; - } - } - } - - private boolean a(BlockPosition blockposition) { - PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); - if (pathtype != PathType.WALKABLE) { - return false; - } else { - IBlockData iblockdata = this.c.getType(blockposition.down()); - if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { - return false; - } else { - BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); - return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); - } - } - } - - private int a(int i, int j) { - return this.a.getRandom().nextInt(j - i + 1) + i; - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; + +import net.minecraft.server.v1_16_R3.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.util.EnumSet; + +public class FoxPathfinderGoalFollowOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityLiving b; + private final IWorldReader c; + private final double d; + private final NavigationAbstract e; + private int f; + private final float g; + private final float h; + private float i; + private final boolean j; + + public FoxPathfinderGoalFollowOwner(EntityTamableFox tamableFox, double d0, float f, float f1, boolean flag) { + this.a = tamableFox; + this.c = tamableFox.world; + this.d = d0; + this.e = tamableFox.getNavigation(); + this.h = f; + this.g = f1; + this.j = flag; + this.a(EnumSet.of(Type.MOVE, Type.LOOK)); + if (!(tamableFox.getNavigation() instanceof Navigation) && !(tamableFox.getNavigation() instanceof NavigationFlying)) { + throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal"); + } + } + + public boolean a() { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else if (entityliving.isSpectator()) { + return false; + } else if (this.a.isSitting()) { // this.a.isWillSit() + return false; + } else if (this.a.h(entityliving) < (double)(this.h * this.h)) { + return false; + } else { + this.b = entityliving; + return true; + } + } + + public boolean b() { + // !this.a.isWillSit() + return !this.e.m() && (!this.a.isSitting() && this.a.h(this.b) > (double) (this.g * this.g)); + } + + public void c() { + this.f = 0; + this.i = this.a.a(PathType.WATER); + this.a.a(PathType.WATER, 0.0F); + } + + public void d() { + this.b = null; + this.e.o(); + this.a.a(PathType.WATER, this.i); + } + + public void e() { + this.a.getControllerLook().a(this.b, 10.0F, (float)this.a.O()); + if (--this.f <= 0) { + this.f = 10; + if (!this.a.isLeashed() && !this.a.isPassenger()) { + if (this.a.h(this.b) >= 144.0D) { + this.g(); + } else { + this.e.a(this.b, this.d); + } + } + } + + } + + private void g() { + BlockPosition blockposition = this.b.getChunkCoordinates(); + + for(int i = 0; i < 10; ++i) { + int j = this.a(-3, 3); + int k = this.a(-1, 1); + int l = this.a(-3, 3); + boolean flag = this.a(blockposition.getX() + j, blockposition.getY() + k, blockposition.getZ() + l); + if (flag) { + return; + } + } + + } + + private boolean a(int i, int j, int k) { + if (Math.abs((double)i - this.b.locX()) < 2.0D && Math.abs((double)k - this.b.locZ()) < 2.0D) { + return false; + } else if (!this.a(new BlockPosition(i, j, k))) { + return false; + } else { + CraftEntity entity = this.a.getBukkitEntity(); + Location to = new Location(entity.getWorld(), (double)i + 0.5D, (double)j, (double)k + 0.5D, this.a.yaw, this.a.pitch); + EntityTeleportEvent event = new EntityTeleportEvent(entity, entity.getLocation(), to); + this.a.world.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } else { + to = event.getTo(); + this.a.setPositionRotation(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch()); + this.e.o(); + return true; + } + } + } + + private boolean a(BlockPosition blockposition) { + PathType pathtype = PathfinderNormal.a(this.c, blockposition.i()); + if (pathtype != PathType.WALKABLE) { + return false; + } else { + IBlockData iblockdata = this.c.getType(blockposition.down()); + if (!this.j && iblockdata.getBlock() instanceof BlockLeaves) { + return false; + } else { + BlockPosition blockposition1 = blockposition.b(this.a.getChunkCoordinates()); + return this.c.getCubes(this.a, this.a.getBoundingBox().a(blockposition1)); + } + } + } + + private int a(int i, int j) { + return this.a.getRandom().nextInt(j - i + 1) + i; + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalHurtByTarget.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalHurtByTarget.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java index b9199bd..7dd1afc 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtByTarget.java @@ -1,46 +1,46 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; - -import net.minecraft.server.v1_16_R3.EntityLiving; -import net.minecraft.server.v1_16_R3.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R3.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.getLastDamager(); - int i = entityliving.da(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.da(); - } - - super.c(); - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; + +import net.minecraft.server.v1_16_R3.EntityLiving; +import net.minecraft.server.v1_16_R3.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R3.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtByTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtByTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { //!this.a.isWillSit + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.getLastDamager(); + int i = entityliving.da(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.TARGET_ATTACKED_OWNER, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.da(); + } + + super.c(); + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java index 4f09755..a826665 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalOwnerHurtTarget.java @@ -1,46 +1,46 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; - -import net.minecraft.server.v1_16_R3.EntityLiving; -import net.minecraft.server.v1_16_R3.PathfinderGoalTarget; -import net.minecraft.server.v1_16_R3.PathfinderTargetCondition; -import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; -import org.bukkit.event.entity.EntityTargetEvent.TargetReason; - -import java.util.EnumSet; - -public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { - private final EntityTamableFox a; - private EntityLiving b; - private int c; - - public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { - super(tamableFox, false); - this.a = tamableFox; - this.a(EnumSet.of(Type.TARGET)); - } - - public boolean a() { - if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() - EntityLiving entityliving = this.a.getOwner(); - if (entityliving == null) { - return false; - } else { - this.b = entityliving.db(); - int i = entityliving.dc(); - return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); - } - } else { - return false; - } - } - - public void c() { - this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); - EntityLiving entityliving = this.a.getOwner(); - if (entityliving != null) { - this.c = entityliving.dc(); - } - - super.c(); - } +package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; + +import net.minecraft.server.v1_16_R3.EntityLiving; +import net.minecraft.server.v1_16_R3.PathfinderGoalTarget; +import net.minecraft.server.v1_16_R3.PathfinderTargetCondition; +import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; + +import java.util.EnumSet; + +public class FoxPathfinderGoalOwnerHurtTarget extends PathfinderGoalTarget { + private final EntityTamableFox a; + private EntityLiving b; + private int c; + + public FoxPathfinderGoalOwnerHurtTarget(EntityTamableFox tamableFox) { + super(tamableFox, false); + this.a = tamableFox; + this.a(EnumSet.of(Type.TARGET)); + } + + public boolean a() { + if (this.a.isTamed() && !this.a.isSitting()) { // !this.a.isWillSit() + EntityLiving entityliving = this.a.getOwner(); + if (entityliving == null) { + return false; + } else { + this.b = entityliving.db(); + int i = entityliving.dc(); + return i != this.c && this.a(this.b, PathfinderTargetCondition.a) && this.a.a(this.b, entityliving); + } + } else { + return false; + } + } + + public void c() { + this.e.setGoalTarget(this.b, TargetReason.OWNER_ATTACKED_TARGET, true); + EntityLiving entityliving = this.a.getOwner(); + if (entityliving != null) { + this.c = entityliving.dc(); + } + + super.c(); + } } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalPanic.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalPanic.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalPanic.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalPanic.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSit.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSit.java similarity index 100% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSit.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSit.java diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java similarity index 97% rename from src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java rename to Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java index 7b90623..3c7134e 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/versions/version_1_16_R3/pathfinding/FoxPathfinderGoalSleepWithOwner.java @@ -1,132 +1,132 @@ -package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; - -import net.minecraft.server.v1_16_R3.*; -import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; - -import java.util.Iterator; -import java.util.List; -import java.util.Random; - -public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { - private final EntityTamableFox a; - private EntityHuman b; - private BlockPosition c; - private int d; - - public FoxPathfinderGoalSleepWithOwner(EntityTamableFox entitycat) { - this.a = entitycat; - } - - public boolean a() { - if (!this.a.isTamed()) { - return false; - } else if (this.a.isSitting()) { - return false; - } else { - EntityLiving entityliving = this.a.getOwner(); - if (entityliving instanceof EntityHuman) { - this.b = (EntityHuman) entityliving; - if (!entityliving.isSleeping()) { - return false; - } - - if (this.a.h(this.b) > 100.0D) { - return false; - } - - BlockPosition blockposition = this.b.getChunkCoordinates(); - IBlockData iblockdata = this.a.world.getType(blockposition); - if (iblockdata.getBlock().a(TagsBlock.BEDS)) { - this.c = (BlockPosition) iblockdata.d(BlockBed.FACING).map((enumdirection) -> { - return blockposition.shift(enumdirection.opposite()); - }).orElseGet(() -> { - return new BlockPosition(blockposition); - }); - return !this.g(); - } - } - - } - return false; - } - - private boolean g() { - List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); - Iterator iterator = list.iterator(); - - EntityTamableFox entitycat; - do { - do { - if (!iterator.hasNext()) { - return false; - } - - entitycat = (EntityTamableFox)iterator.next(); - } while(entitycat == this.a); - } while(!entitycat.eW()); - - return true; - } - - public boolean b() { - return this.a.isTamed() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); - } - - public void c() { - if (this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - } - - } - - public void d() { - this.a.setSleeping(false); - float f = this.a.world.f(1.0F); - if (this.b.eC() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { - this.h(); - } - - this.d = 0; - //this.a.y(false); - this.a.getNavigation().o(); - } - - private void h() { - Random random = this.a.getRandom(); - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); - blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); - LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); - net.minecraft.server.v1_16_R3.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R3.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.ORIGIN, this.a.getPositionVector()).set(LootContextParameters.THIS_ENTITY, this.a).a(random); - List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); - Iterator iterator = list.iterator(); - - while(iterator.hasNext()) { - ItemStack itemstack = (ItemStack)iterator.next(); - this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aA * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aA * 0.017453292F), itemstack)); - } - - } - - public void e() { - if (this.b != null && this.c != null) { - this.a.setSitting(false); - this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); - if (this.a.h(this.b) < 2.5D) { - ++this.d; - if (this.d > 16) { - this.a.setSleeping(true); - //this.a.y(false); - } else { - this.a.a(this.b, 45.0F, 45.0F); - //this.a.y(true); - } - } else { - this.a.setSleeping(false); - } - } - - } -} +package net.seanomik.tamablefoxes.versions.version_1_16_R3.pathfinding; + +import net.minecraft.server.v1_16_R3.*; +import net.seanomik.tamablefoxes.versions.version_1_16_R3.EntityTamableFox; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +public class FoxPathfinderGoalSleepWithOwner extends PathfinderGoal { + private final EntityTamableFox a; + private EntityHuman b; + private BlockPosition c; + private int d; + + public FoxPathfinderGoalSleepWithOwner(EntityTamableFox entitycat) { + this.a = entitycat; + } + + public boolean a() { + if (!this.a.isTamed()) { + return false; + } else if (this.a.isSitting()) { + return false; + } else { + EntityLiving entityliving = this.a.getOwner(); + if (entityliving instanceof EntityHuman) { + this.b = (EntityHuman) entityliving; + if (!entityliving.isSleeping()) { + return false; + } + + if (this.a.h(this.b) > 100.0D) { + return false; + } + + BlockPosition blockposition = this.b.getChunkCoordinates(); + IBlockData iblockdata = this.a.world.getType(blockposition); + if (iblockdata.getBlock().a(TagsBlock.BEDS)) { + this.c = (BlockPosition) iblockdata.d(BlockBed.FACING).map((enumdirection) -> { + return blockposition.shift(enumdirection.opposite()); + }).orElseGet(() -> { + return new BlockPosition(blockposition); + }); + return !this.g(); + } + } + + } + return false; + } + + private boolean g() { + List list = this.a.world.a(EntityTamableFox.class, (new AxisAlignedBB(this.c)).g(2.0D)); + Iterator iterator = list.iterator(); + + EntityTamableFox entitycat; + do { + do { + if (!iterator.hasNext()) { + return false; + } + + entitycat = (EntityTamableFox)iterator.next(); + } while(entitycat == this.a); + } while(!entitycat.eW()); + + return true; + } + + public boolean b() { + return this.a.isTamed() && this.b != null && this.b.isSleeping() && this.c != null && !this.g(); + } + + public void c() { + if (this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + } + + } + + public void d() { + this.a.setSleeping(false); + float f = this.a.world.f(1.0F); + if (this.b.eC() >= 100 && (double)f > 0.77D && (double)f < 0.8D && (double)this.a.world.getRandom().nextFloat() < 0.7D) { + this.h(); + } + + this.d = 0; + //this.a.y(false); + this.a.getNavigation().o(); + } + + private void h() { + Random random = this.a.getRandom(); + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + this.a.a((double)(blockposition_mutableblockposition.getX() + random.nextInt(11) - 5), (double)(blockposition_mutableblockposition.getY() + random.nextInt(5) - 2), (double)(blockposition_mutableblockposition.getZ() + random.nextInt(11) - 5), false); + blockposition_mutableblockposition.g(this.a.getChunkCoordinates()); + LootTable loottable = this.a.world.getMinecraftServer().getLootTableRegistry().getLootTable(LootTables.ak); + net.minecraft.server.v1_16_R3.LootTableInfo.Builder loottableinfo_builder = (new net.minecraft.server.v1_16_R3.LootTableInfo.Builder((WorldServer)this.a.world)).set(LootContextParameters.ORIGIN, this.a.getPositionVector()).set(LootContextParameters.THIS_ENTITY, this.a).a(random); + List list = loottable.populateLoot(loottableinfo_builder.build(LootContextParameterSets.GIFT)); + Iterator iterator = list.iterator(); + + while(iterator.hasNext()) { + ItemStack itemstack = (ItemStack)iterator.next(); + this.a.world.addEntity(new EntityItem(this.a.world, (double)blockposition_mutableblockposition.getX() - (double)MathHelper.sin(this.a.aA * 0.017453292F), (double)blockposition_mutableblockposition.getY(), (double)blockposition_mutableblockposition.getZ() + (double)MathHelper.cos(this.a.aA * 0.017453292F), itemstack)); + } + + } + + public void e() { + if (this.b != null && this.c != null) { + this.a.setSitting(false); + this.a.getNavigation().a((double)this.c.getX(), (double)this.c.getY(), (double)this.c.getZ(), 1.100000023841858D); + if (this.a.h(this.b) < 2.5D) { + ++this.d; + if (this.d > 16) { + this.a.setSleeping(true); + //this.a.y(false); + } else { + this.a.a(this.b, 45.0F, 45.0F); + //this.a.y(true); + } + } else { + this.a.setSleeping(false); + } + } + + } +} diff --git a/src/main/resources/config.yml b/Plugin/src/main/resources/config.yml similarity index 78% rename from src/main/resources/config.yml rename to Plugin/src/main/resources/config.yml index 5c59195..2c2faf2 100644 --- a/src/main/resources/config.yml +++ b/Plugin/src/main/resources/config.yml @@ -1,7 +1,7 @@ -# Config for Tamable Foxes -show-owner-in-fox-name: true -ask-for-name-after-taming: true -max-fox-tames: 0 - -tamed-behavior: +# Config for Tamable Foxes +show-owner-in-fox-name: true +ask-for-name-after-taming: true +max-fox-tames: 0 + +tamed-behavior: attack-wild-animals: true \ No newline at end of file diff --git a/src/main/resources/language.yml b/Plugin/src/main/resources/language.yml similarity index 96% rename from src/main/resources/language.yml rename to Plugin/src/main/resources/language.yml index 2f90b1e..b99a656 100644 --- a/src/main/resources/language.yml +++ b/Plugin/src/main/resources/language.yml @@ -1,19 +1,19 @@ -mc-version-loading: "Registering entity for MC Version %MC_VERSION%..." -unsupported-mc-version-not-registering: "ERROR: This plugin version only supports Spigot 1.14-1.16.4! Not registering entity! Make sure your Java version is no newer than Java 11!" -unsupported-mc-version-disabling: "This plugin version only supports Spigot 1.14-1.16.4! Disabling plugin! Make sure your Java version is no newer than Java 11!" -success-replaced-entity: "Replaced tamable fox entity!" -error-to-replaced-entity: "Failed to replace tamable fox entity!" -saving-foxes-message: "Saving foxes." - -taming-tamed-message: "You just tamed a wild fox!" -taming-asking-for-name-message: "What do you want to call it?" -taming-chosen-name-perfect: "%NEW_FOX_NAME% is perfect!" -fox-name-format: "%FOX_NAME% (%OWNER%'s Fox)" -fox-name-no-owner-name-format: "%FOX_NAME%" -fox-doesnt-trust: "The fox doesn't trust you! You have too many foxes!" - -no-permission: "You do not have the permission for this command." -only-run-by-player: "Command can only be run from player state!" -spawned-fox-message: "Spawned a %TYPE% fox." -failed-to-spawn-message: "Failed to spawn fox!" +mc-version-loading: "Registering entity for MC Version %MC_VERSION%..." +unsupported-mc-version-not-registering: "ERROR: This plugin version only supports Spigot 1.14-1.16.4! Not registering entity! Make sure your Java version is no newer than Java 11!" +unsupported-mc-version-disabling: "This plugin version only supports Spigot 1.14-1.16.4! Disabling plugin! Make sure your Java version is no newer than Java 11!" +success-replaced-entity: "Replaced tamable fox entity!" +error-to-replaced-entity: "Failed to replace tamable fox entity!" +saving-foxes-message: "Saving foxes." + +taming-tamed-message: "You just tamed a wild fox!" +taming-asking-for-name-message: "What do you want to call it?" +taming-chosen-name-perfect: "%NEW_FOX_NAME% is perfect!" +fox-name-format: "%FOX_NAME% (%OWNER%'s Fox)" +fox-name-no-owner-name-format: "%FOX_NAME%" +fox-doesnt-trust: "The fox doesn't trust you! You have too many foxes!" + +no-permission: "You do not have the permission for this command." +only-run-by-player: "Command can only be run from player state!" +spawned-fox-message: "Spawned a %TYPE% fox." +failed-to-spawn-message: "Failed to spawn fox!" reloaded-message: "Reloaded." \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml similarity index 97% rename from src/main/resources/plugin.yml rename to Plugin/src/main/resources/plugin.yml index e17b52b..29526f6 100644 --- a/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -1,22 +1,22 @@ -name: Tamablefoxes -version: ${project.version} -main: net.seanomik.tamablefoxes.TamableFoxes -api-version: 1.14 -load: STARTUP -description: Adds tamable foxes to Minecraft! - -commands: - spawntamablefox: - aliases: [tamablefox, stf, spawntf] - usage: /spawntamablefox [type] - description: Spawn a tamable fox at the standing location. Type can be snow or red, or left empty for a red. -permissions: - tamablefoxes.spawn: - description: "Gives the player the ability to spawn tamable foxes." - default: op - tamablefoxes.tame: - description: "Gives the player the ability to tame a fox." - default: true - tamablefoxes.tame.unlimited: - description: "Lets players bypass the tame limit." - default: op +name: Tamablefoxes +version: ${project.version} +main: net.seanomik.tamablefoxes.TamableFoxes +api-version: 1.14 +load: STARTUP +description: Adds tamable foxes to Minecraft! + +commands: + spawntamablefox: + aliases: [tamablefox, stf, spawntf] + usage: /spawntamablefox [type] + description: Spawn a tamable fox at the standing location. Type can be snow or red, or left empty for a red. +permissions: + tamablefoxes.spawn: + description: "Gives the player the ability to spawn tamable foxes." + default: op + tamablefoxes.tame: + description: "Gives the player the ability to tame a fox." + default: true + tamablefoxes.tame.unlimited: + description: "Lets players bypass the tame limit." + default: op diff --git a/Utility/pom.xml b/Utility/pom.xml new file mode 100644 index 0000000..b7bc63f --- /dev/null +++ b/Utility/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + + net.seanomik + tamablefoxes-parent + 2.0.0-SNAPSHOT + + + tamablefoxes-util + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.14-R0.1-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java similarity index 92% rename from src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java index 2529016..288cd16 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/FieldHelper.java @@ -1,12 +1,10 @@ -package net.seanomik.tamablefoxes.versions; +package net.seanomik.tamablefoxes.util; -import net.seanomik.tamablefoxes.Utils; -import net.seanomik.tamablefoxes.io.LanguageConfig; +import net.seanomik.tamablefoxes.util.io.LanguageConfig; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.invoke.VarHandle; import java.lang.reflect.Field; import java.lang.reflect.Modifier; diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/NMSInterface.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java similarity index 58% rename from src/main/java/net/seanomik/tamablefoxes/versions/NMSInterface.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java index c895e06..9ed6191 100644 --- a/src/main/java/net/seanomik/tamablefoxes/versions/NMSInterface.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/NMSInterface.java @@ -1,15 +1,13 @@ -package net.seanomik.tamablefoxes.versions; - -//import net.minecraft.server.v1_15_R1.EntityFox; -import net.seanomik.tamablefoxes.TamableFoxes; -import org.bukkit.Location; - -public interface NMSInterface { - enum FoxType { - RED, - SNOW - } - - public void registerCustomFoxEntity(); - public void spawnTamableFox(Location loc, FoxType type); +package net.seanomik.tamablefoxes.util; + +import org.bukkit.Location; + +public interface NMSInterface { + enum FoxType { + RED, + SNOW + } + + public void registerCustomFoxEntity(); + public void spawnTamableFox(Location loc, FoxType type); } \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/Utils.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/Utils.java similarity index 93% rename from src/main/java/net/seanomik/tamablefoxes/Utils.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/Utils.java index 9938e9c..d91f69c 100644 --- a/src/main/java/net/seanomik/tamablefoxes/Utils.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/Utils.java @@ -1,51 +1,53 @@ -package net.seanomik.tamablefoxes; - -import org.bukkit.ChatColor; - -import java.lang.reflect.Constructor; -import java.util.List; - -public class Utils { - public static String getPrefix() { - return ChatColor.RED + "[Tamable Foxes] "; - } - - public static Class getPrivateInnerClass(Class outer, String innerName) { - for (Class declaredClass : outer.getDeclaredClasses()) { - if (declaredClass.getSimpleName().equals(innerName)) return declaredClass; - } - - return null; - } - - public static Object instantiatePrivateInnerClass(Class outer, String innerName, Object outerObject, List args, List> argTypes) { - try { - Class innerClass = getPrivateInnerClass(outer, innerName); - - Object[] argObjects = new Object[args.size() + 1]; - Class[] argClasses = new Class[argTypes.size() + 1]; - - // Needed due to how List#toArray() converts the classes to objects - for (int i = 0; i < argClasses.length; i++) { - if (i == argClasses.length - 1) continue; - argObjects[i + 1] = args.get(i); - argClasses[i + 1] = argTypes.get(i); - } - argObjects[0] = outerObject; - argClasses[0] = outer; - - Constructor innerConstructor = innerClass.getDeclaredConstructor(argClasses); - innerConstructor.setAccessible(true); - - Object instantiatedClass = innerConstructor.newInstance(argObjects); - - innerConstructor.setAccessible(false); - - return instantiatedClass; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - -} +package net.seanomik.tamablefoxes.util; + +import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.Constructor; +import java.util.List; + +public class Utils { + public static String getPrefix() { + return ChatColor.RED + "[Tamable Foxes] "; + } + public static Plugin tamableFoxesPlugin; + + public static Class getPrivateInnerClass(Class outer, String innerName) { + for (Class declaredClass : outer.getDeclaredClasses()) { + if (declaredClass.getSimpleName().equals(innerName)) return declaredClass; + } + + return null; + } + + public static Object instantiatePrivateInnerClass(Class outer, String innerName, Object outerObject, List args, List> argTypes) { + try { + Class innerClass = getPrivateInnerClass(outer, innerName); + + Object[] argObjects = new Object[args.size() + 1]; + Class[] argClasses = new Class[argTypes.size() + 1]; + + // Needed due to how List#toArray() converts the classes to objects + for (int i = 0; i < argClasses.length; i++) { + if (i == argClasses.length - 1) continue; + argObjects[i + 1] = args.get(i); + argClasses[i + 1] = argTypes.get(i); + } + argObjects[0] = outerObject; + argClasses[0] = outer; + + Constructor innerConstructor = innerClass.getDeclaredConstructor(argClasses); + innerConstructor.setAccessible(true); + + Object instantiatedClass = innerConstructor.newInstance(argObjects); + + innerConstructor.setAccessible(false); + + return instantiatedClass; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/src/main/java/net/seanomik/tamablefoxes/io/Config.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/Config.java similarity index 82% rename from src/main/java/net/seanomik/tamablefoxes/io/Config.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/io/Config.java index 9d6e764..275d9df 100644 --- a/src/main/java/net/seanomik/tamablefoxes/io/Config.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/Config.java @@ -1,11 +1,14 @@ -package net.seanomik.tamablefoxes.io; +package net.seanomik.tamablefoxes.util.io; -import net.seanomik.tamablefoxes.TamableFoxes; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; public class Config { - private static FileConfiguration config = TamableFoxes.getPlugin().getConfig(); + private static FileConfiguration config = null; + + public static void setConfig(FileConfiguration config) { + Config.config = config; + } // Does the owner's name show if the foxes name? public static boolean doesShowOwnerInFoxName() { return config.getBoolean("show-owner-in-fox-name"); } diff --git a/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java similarity index 66% rename from src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java index 415b84b..e5e8c97 100644 --- a/src/main/java/net/seanomik/tamablefoxes/io/LanguageConfig.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/LanguageConfig.java @@ -1,161 +1,161 @@ -package net.seanomik.tamablefoxes.io; - -import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.versions.NMSInterface; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; - -public class LanguageConfig extends YamlConfiguration { - private static LanguageConfig config; - private TamableFoxes plugin; - private File configFile; - - public static LanguageConfig getConfig() { - if (LanguageConfig.config == null) { - LanguageConfig.config = new LanguageConfig(); - } - return LanguageConfig.config; - } - - public LanguageConfig() { - this.plugin = TamableFoxes.getPlugin(); - this.configFile = new File(this.plugin.getDataFolder(), "language.yml"); - this.saveDefault(); - this.reload(); - } - - public void reload() { - try { - super.load(this.configFile); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void save() { - try { - super.save(this.configFile); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void saveDefault() { - this.plugin.saveResource("language.yml", false); - } - - public void saveConfig() { - try { - super.save(this.configFile); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void reloadConfig() { - try { - super.load(this.configFile); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public void saveDefaultConfig() { - try { - this.plugin.saveDefaultConfig(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - // Auto replace alternate color codes. - @Override - public String getString(String path) { - // Only attempt to translate if the text is not empty. - return (super.getString(path).isEmpty()) ? super.getString(path) : ChatColor.translateAlternateColorCodes('&', super.getString(path)); - } - - // This is the text that shows when registering the custom entity - public static String getMCVersionLoading(String mcVersionStr) { - return getConfig().getString("mc-version-loading").replaceAll("%MC_VERSION%", mcVersionStr); - } - - // Get the error that shows during register when they try to run the plugin on an unsupported mc version. - public static String getUnsupportedMCVersionRegister() { - return getConfig().getString("unsupported-mc-version-not-registering"); - } - - // Get the error that shows during disable when they try to run the plugin on an unsupported mc version. - public static String getUnsupportedMCVersionDisable() { - return getConfig().getString("unsupported-mc-version-disabling"); - } - - // Get the message that shows when we successfully replaced the entity. - public static String getSuccessReplaced() { - return getConfig().getString("success-replaced-entity"); - } - - // Get the error when it failed to replace the entity. - public static String getFailureReplace() { - return getConfig().getString("error-to-replaced-entity"); - } - - // Get the message when saving foxes. - public static String getSavingFoxMessage() { - return getConfig().getString("saving-foxes-message"); - } - - // Get the message that shows when you tame a fox. - public static String getTamedMessage() { - return getConfig().getString("taming-tamed-message"); - } - - // Get the message when you ask for the foxes name. - public static String getTamingAskingName() { - return getConfig().getString("taming-asking-for-name-message"); - } - - // Get the message when you give feed back on the new fox name. - public static String getTamingChosenPerfect(String chosen) { - return getConfig().getString("taming-chosen-name-perfect").replaceAll("%NEW_FOX_NAME%", chosen); - } - - // Get the fox name format. - public static String getFoxNameFormat(String foxName, String ownerName) { - return getConfig().getString((Config.doesShowOwnerInFoxName()) ? "fox-name-format" : "fox-name-no-owner-name-format").replaceAll("%FOX_NAME%", foxName).replaceAll("%OWNER%", ownerName); - } - - public static String getFoxDoesntTrust() { - return getConfig().getString("fox-doesnt-trust"); - } - - public static String getNoPermMessage() { - return getConfig().getString("no-permission"); - } - - public static String getOnlyRunPlayer() { - return getConfig().getString("only-run-by-player"); - } - - public static String getSpawnedFoxMessage(NMSInterface.FoxType type) { - String typeStr = ((type == type.SNOW) ? ChatColor.AQUA + "Snow" : ChatColor.RED + "Red") + ChatColor.RESET; - return getConfig().getString("spawned-fox-message").replaceAll("%TYPE%", typeStr); - } - - public static String getFailureSpawn() { - return getConfig().getString("failed-to-spawn-message"); - } - - public static String getReloadMessage() { - return getConfig().getString("reloaded-message"); - } -} - +package net.seanomik.tamablefoxes.util.io; + +import net.seanomik.tamablefoxes.util.NMSInterface; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; + +public class LanguageConfig extends YamlConfiguration { + private static LanguageConfig config; + private JavaPlugin plugin; + private File configFile; + + public static LanguageConfig getConfig(JavaPlugin plugin) { + if (LanguageConfig.config == null) { + LanguageConfig.config = new LanguageConfig(plugin); + } + return LanguageConfig.config; + } + + public LanguageConfig(JavaPlugin plugin) { + this.plugin = plugin; + this.configFile = new File(this.plugin.getDataFolder(), "language.yml"); + this.saveDefault(); + this.reload(); + } + + public void reload() { + try { + super.load(this.configFile); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public void save() { + try { + super.save(this.configFile); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public void saveDefault() { + this.plugin.saveResource("language.yml", false); + } + + public void saveConfig() { + try { + super.save(this.configFile); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public void reloadConfig() { + try { + super.load(this.configFile); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + public void saveDefaultConfig() { + try { + this.plugin.saveDefaultConfig(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + // Auto replace alternate color codes. + @Override + public String getString(String path) { + // Only attempt to translate if the text is not empty. + return (super.getString(path).isEmpty()) ? super.getString(path) : ChatColor.translateAlternateColorCodes('&', super.getString(path)); + } + + // This is the text that shows when registering the custom entity + public static String getMCVersionLoading(String mcVersionStr) { + return config.getString("mc-version-loading").replaceAll("%MC_VERSION%", mcVersionStr); + } + + // Get the error that shows during register when they try to run the plugin on an unsupported mc version. + public static String getUnsupportedMCVersionRegister() { + return config.getString("unsupported-mc-version-not-registering"); + } + + // Get the error that shows during disable when they try to run the plugin on an unsupported mc version. + public static String getUnsupportedMCVersionDisable() { + return config.getString("unsupported-mc-version-disabling"); + } + + // Get the message that shows when we successfully replaced the entity. + public static String getSuccessReplaced() { + return config.getString("success-replaced-entity"); + } + + // Get the error when it failed to replace the entity. + public static String getFailureReplace() { + return config.getString("error-to-replaced-entity"); + } + + // Get the message when saving foxes. + public static String getSavingFoxMessage() { + return config.getString("saving-foxes-message"); + } + + // Get the message that shows when you tame a fox. + public static String getTamedMessage() { + return config.getString("taming-tamed-message"); + } + + // Get the message when you ask for the foxes name. + public static String getTamingAskingName() { + return config.getString("taming-asking-for-name-message"); + } + + // Get the message when you give feed back on the new fox name. + public static String getTamingChosenPerfect(String chosen) { + return config.getString("taming-chosen-name-perfect").replaceAll("%NEW_FOX_NAME%", chosen); + } + + // Get the fox name format. + public static String getFoxNameFormat(String foxName, String ownerName) { + return config.getString((Config.doesShowOwnerInFoxName()) ? "fox-name-format" : "fox-name-no-owner-name-format").replaceAll("%FOX_NAME%", foxName).replaceAll("%OWNER%", ownerName); + } + + public static String getFoxDoesntTrust() { + return config.getString("fox-doesnt-trust"); + } + + public static String getNoPermMessage() { + return config.getString("no-permission"); + } + + public static String getOnlyRunPlayer() { + return config.getString("only-run-by-player"); + } + + public static String getSpawnedFoxMessage(NMSInterface.FoxType type) { + String typeStr = ((type == type.SNOW) ? ChatColor.AQUA + "Snow" : ChatColor.RED + "Red") + ChatColor.RESET; + return config.getString("spawned-fox-message").replaceAll("%TYPE%", typeStr); + } + + public static String getFailureSpawn() { + return config.getString("failed-to-spawn-message"); + } + + public static String getReloadMessage() { + return config.getString("reloaded-message"); + } +} + \ No newline at end of file diff --git a/src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHandler.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHandler.java similarity index 72% rename from src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHandler.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHandler.java index 5449e25..56ba9e7 100644 --- a/src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHandler.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHandler.java @@ -1,58 +1,61 @@ -package net.seanomik.tamablefoxes.io.sqlite; - -import net.seanomik.tamablefoxes.TamableFoxes; -import org.bukkit.Bukkit; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; - -public class SQLiteHandler { - private Connection connection; - - private static SQLiteHandler instance; - - public static SQLiteHandler getInstance() { - if (instance == null) { - instance = new SQLiteHandler(); - } - - return instance; - } - - public void connect() { - try { - String pluginFolder = TamableFoxes.getPlugin().getDataFolder().getAbsolutePath(); - String url = "jdbc:sqlite:" + pluginFolder + "/userFoxAmount.db"; - connection = DriverManager.getConnection(url); - - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public Connection getConnection() { - return connection; - } - - public void closeConnection() { - try { - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void newConnection() { - try { - connection.close(); - connect(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void setConnection(Connection connection) { - this.connection = connection; - } -} +package net.seanomik.tamablefoxes.util.io.sqlite; + +import org.bukkit.plugin.Plugin; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class SQLiteHandler { + private Connection connection; + + private static SQLiteHandler instance; + + public static SQLiteHandler getInstance() { + if (instance == null) { + instance = new SQLiteHandler(); + } + + return instance; + } + + public void connect(Plugin plugin) { + String pluginFolder = plugin.getDataFolder().getAbsolutePath(); + connect(pluginFolder); + } + + public void connect(String pluginFolder) { + try { + String url = "jdbc:sqlite:" + pluginFolder + "/userFoxAmount.db"; + connection = DriverManager.getConnection(url); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public Connection getConnection() { + return connection; + } + + public void closeConnection() { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void newConnection(String pluginFolder) { + try { + connection.close(); + connect(pluginFolder); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void setConnection(Connection connection) { + this.connection = connection; + } +} diff --git a/src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHelper.java b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHelper.java similarity index 90% rename from src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHelper.java rename to Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHelper.java index 95c1e1b..816ee51 100644 --- a/src/main/java/net/seanomik/tamablefoxes/io/sqlite/SQLiteHelper.java +++ b/Utility/src/main/java/net/seanomik/tamablefoxes/util/io/sqlite/SQLiteHelper.java @@ -1,130 +1,130 @@ -package net.seanomik.tamablefoxes.io.sqlite; - -import net.seanomik.tamablefoxes.TamableFoxes; -import net.seanomik.tamablefoxes.Utils; -import org.bukkit.plugin.Plugin; - -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; - -public class SQLiteHelper { - public static Plugin plugin; - public static SQLiteHandler sqLiteHandler; - - private static SQLiteHelper instance; - private static String userAmountTableName = "USER_FOX_AMT"; - - public static SQLiteHelper getInstance() { - if (instance == null) { - instance = new SQLiteHelper(); - } - - return instance; - } - - public void createTablesIfNotExist() { - sqLiteHandler = SQLiteHandler.getInstance(); - - String userFoxAmountQuery = - "CREATE TABLE IF NOT EXISTS `" + userAmountTableName + "` ( " + - "`UUID` TEXT PRIMARY KEY , " + - "`AMOUNT` INT NOT NULL);"; - - try { - sqLiteHandler.connect(); - // Create previous bans table - DatabaseMetaData dbm = sqLiteHandler.getConnection().getMetaData(); - ResultSet tables = dbm.getTables(null, null, userAmountTableName, null); - if (!tables.next()) { - PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(userFoxAmountQuery); - statement.executeUpdate(); - - plugin.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + "Created previous player bans table!"); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - if (sqLiteHandler.getConnection() != null) { - try { - sqLiteHandler.getConnection().close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - public int getPlayerFoxAmount(UUID uuid) { - try { - sqLiteHandler.connect(); - PreparedStatement statement = sqLiteHandler.getConnection() - .prepareStatement("SELECT * FROM " + userAmountTableName + " WHERE UUID=?"); - statement.setString(1, uuid.toString()); - ResultSet results = statement.executeQuery(); - - if (results.next()) { - return results.getInt("AMOUNT"); - } - } catch (SQLException e) { - e.printStackTrace(); - } finally { - if (sqLiteHandler.getConnection() != null) { - try { - sqLiteHandler.getConnection().close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - return -1; - } - - public void addPlayerFoxAmount(UUID uuid, int amt) { - try { - String query = "UPDATE " + userAmountTableName + " SET AMOUNT = AMOUNT + " + amt + " WHERE UUID = '" + uuid.toString() + "'"; - if (getPlayerFoxAmount(uuid) == -1) { - query = "INSERT INTO " + userAmountTableName + " (UUID, AMOUNT) VALUES('" + uuid.toString() + "'," + amt + ")"; - } - - sqLiteHandler.connect(); - PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(query); - - statement.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } finally { - if (sqLiteHandler.getConnection() != null) { - try { - sqLiteHandler.getConnection().close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - - public void removePlayerFoxAmount(UUID uuid, int amt) { - try { - String query = "UPDATE " + userAmountTableName + " SET AMOUNT = AMOUNT - " + amt + " WHERE UUID = '" + uuid.toString() + "'"; - - sqLiteHandler.connect(); - PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(query); - - statement.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } finally { - if (sqLiteHandler.getConnection() != null) { - try { - sqLiteHandler.getConnection().close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } -} +package net.seanomik.tamablefoxes.util.io.sqlite; + +import net.seanomik.tamablefoxes.util.Utils; +import org.bukkit.plugin.Plugin; + +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +public class SQLiteHelper { + public static Plugin plugin; + public static SQLiteHandler sqLiteHandler; + + private static SQLiteHelper instance; + private static String userAmountTableName = "USER_FOX_AMT"; + + public static SQLiteHelper getInstance(Plugin plugin) { + if (instance == null) { + instance = new SQLiteHelper(); + instance.plugin = plugin; + } + + return instance; + } + + public void createTablesIfNotExist() { + sqLiteHandler = SQLiteHandler.getInstance(); + + String userFoxAmountQuery = + "CREATE TABLE IF NOT EXISTS `" + userAmountTableName + "` ( " + + "`UUID` TEXT PRIMARY KEY , " + + "`AMOUNT` INT NOT NULL);"; + + try { + sqLiteHandler.connect(plugin); + // Create previous bans table + DatabaseMetaData dbm = sqLiteHandler.getConnection().getMetaData(); + ResultSet tables = dbm.getTables(null, null, userAmountTableName, null); + if (!tables.next()) { + PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(userFoxAmountQuery); + statement.executeUpdate(); + + plugin.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + "Created previous player bans table!"); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (sqLiteHandler.getConnection() != null) { + try { + sqLiteHandler.getConnection().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + public int getPlayerFoxAmount(UUID uuid) { + try { + sqLiteHandler.connect(plugin); + PreparedStatement statement = sqLiteHandler.getConnection() + .prepareStatement("SELECT * FROM " + userAmountTableName + " WHERE UUID=?"); + statement.setString(1, uuid.toString()); + ResultSet results = statement.executeQuery(); + + if (results.next()) { + return results.getInt("AMOUNT"); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (sqLiteHandler.getConnection() != null) { + try { + sqLiteHandler.getConnection().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + return -1; + } + + public void addPlayerFoxAmount(UUID uuid, int amt) { + try { + String query = "UPDATE " + userAmountTableName + " SET AMOUNT = AMOUNT + " + amt + " WHERE UUID = '" + uuid.toString() + "'"; + if (getPlayerFoxAmount(uuid) == -1) { + query = "INSERT INTO " + userAmountTableName + " (UUID, AMOUNT) VALUES('" + uuid.toString() + "'," + amt + ")"; + } + + sqLiteHandler.connect(plugin); + PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(query); + + statement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (sqLiteHandler.getConnection() != null) { + try { + sqLiteHandler.getConnection().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + public void removePlayerFoxAmount(UUID uuid, int amt) { + try { + String query = "UPDATE " + userAmountTableName + " SET AMOUNT = AMOUNT - " + amt + " WHERE UUID = '" + uuid.toString() + "'"; + + sqLiteHandler.connect(plugin); + PreparedStatement statement = sqLiteHandler.getConnection().prepareStatement(query); + + statement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (sqLiteHandler.getConnection() != null) { + try { + sqLiteHandler.getConnection().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } +} diff --git a/pom.xml b/pom.xml index 2fd0769..d97571d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,98 +5,51 @@ 4.0.0 net.seanomik - tamablefoxes - 1.9.2.1-SNAPSHOT - jar + tamablefoxes-parent + 2.0.0-SNAPSHOT + pom - Tamablefoxes + + Plugin + Utility + 1_17_R1 + - 8 + 16 + 16 + UTF-8 - clean package - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - - package - - shade - - - - - - - - - - - - - D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.5_\plugins\TamableFoxes_v${project.version}.jar - false - - - - - - - - src/main/resources - true - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - sonatype - https://oss.sonatype.org/content/groups/public/ - - - codemc-snapshots - https://repo.codemc.io/repository/maven-snapshots/ - - - - - - local.spigot.nms - AllSpigotNMS - LATEST - system - ${project.basedir}/Spigot_v14_v15_v16-v165.jar - - - org.spigotmc - spigot-api - 1.14.4-R0.1-SNAPSHOT - provided - - - net.wesjd - anvilgui - 1.5.0-SNAPSHOT - - - + \ No newline at end of file