diff --git a/.gitignore b/.gitignore index cb2922e..ba64e36 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,8 @@ dependency-reduced-pom.xml # IDEA-specific /.idea/ +mydog.iml # Maven build /target/ +/.mvn/ diff --git a/.travis.yml b/.travis.yml index 05d1221..9e5e879 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,6 @@ after_failure: addons: sonarcloud: organization: "doggycraftdk" - token: - secure: $SONAR_TOKEN script: - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=DoggyCraftDK_MyDog \ No newline at end of file diff --git a/pom.xml b/pom.xml index aa92de6..de1351d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,75 +1,83 @@ - 4.0.0 - dk.fido2603 - mydog - 0.0.9 - MyDog - Tamed wolves but at least 10x better! - https://github.com/DoggyCraftDK/MyDog - jar - - - MIT License - https://raw.githubusercontent.com/DoggyCraftDK/MyDog/master/LICENSE - - - - 1.8 - 1.8 - 1.8 - UTF-8 - http://localhost:9000/ - - ${dependency.check.report.dir}/dependency-check-report.xml - - ${dependency.check.report.dir}/dependency-check-report.html - + 4.0.0 + dk.fido2603 + mydog + 0.1.0 + MyDog + Tamed wolves but at least 10x better! + https://github.com/DoggyCraftDK/MyDog + jar + + + MIT License + https://raw.githubusercontent.com/DoggyCraftDK/MyDog/master/LICENSE + + + + + github + GitHub DoggyCraftDK Apache Maven Packages + https://maven.pkg.github.com/DoggyCraftDK/MyDog + + + + 1.8 + 1.8 + 1.8 + UTF-8 + http://localhost:9000/ + + ${dependency.check.report.dir}/dependency-check-report.xml + + ${dependency.check.report.dir}/dependency-check-report.html + + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots - vault-repo - http://nexus.hc.to/content/repositories/pub_releases + vault-repo + http://nexus.hc.to/content/repositories/pub_releases - - - + + + - org.spigotmc - spigot-api - 1.14.4-R0.1-SNAPSHOT - provided + org.spigotmc + spigot-api + 1.15.2-R0.1-SNAPSHOT + provided - + - net.milkbowl.vault - VaultAPI - 1.7 - provided + net.milkbowl.vault + VaultAPI + 1.7 + provided - - - clean package - ${project.name}-${project.version} - ${project.basedir}/src/ - - - true - ${project.basedir}/src/resources - - *.yml - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.1 - - - + + + clean package + ${project.name}-${project.version} + ${project.basedir}/src/ + + + true + ${project.basedir}/src/resources + + *.yml + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + \ No newline at end of file diff --git a/src/dk/fido2603/mydog/MyDog.java b/src/dk/fido2603/mydog/MyDog.java index 2a480e9..e316199 100644 --- a/src/dk/fido2603/mydog/MyDog.java +++ b/src/dk/fido2603/mydog/MyDog.java @@ -37,6 +37,8 @@ public class MyDog extends JavaPlugin public boolean debug = false; public boolean instantSave = false; public boolean teleportOnWorldChange = true; + public boolean teleportAllTameables = false; + public boolean expandedSearch = false; public boolean onlyShowNametagOnHover = false; public boolean allowPlayerKillExp = true; @@ -44,7 +46,7 @@ public class MyDog extends JavaPlugin public String levelUpSound = "ENTITY_WOLF_HOWL"; public String levelUpString = "&5&l[{chatPrefix}] &r&5Your dog, {dogNameColor}{dogName}&5, just leveled up to &dLevel {level}&5!"; - public String cannotTeleportWolfString = "&c&l[{chatPrefix}] &r&cHello! Looks like you just teleported away from your Dog(s)! " + + public String cannotTeleportTameableString = "&c&l[{chatPrefix}] &r&cHello! Looks like you just teleported away from your Pet(s)! " + "They can sadly not find a safe place to stay, so they are staying behind for now :( They will be waiting for you where you left them..."; public String newDogString = "&6&l[{chatPrefix}] &r&6Congratulations with your new dog, {dogNameColor}{dogName}&6!"; public String deadDogString = "&c&l[{chatPrefix}] &r&cYour dog, {dogNameColor}{dogName}&c, just passed away... {dogNameColor}{dogName}&c lived for {time}{deadDogLevelString}."; @@ -102,8 +104,7 @@ public class MyDog extends JavaPlugin "Sparky", "Spencer", "Spike", "Spot", "Stanley", "Stewie", "Storm", "Taco", "Tank", "Taz", "Teddy", "Tesla", "Theo", "Thor", "Titus", "TJ", "Toby", "Trapper", "Tripp", "Tucker", "Tyler", "Tyson", "Vince", "Vinnie", "Wally", "Walter", "Watson", "Willy", "Winston", "Woody", "Wrigley", "Wyatt", "Yogi", "Yoshi", "Yukon", - "Zane", "Zeus", "Ziggy" - ); + "Zane", "Zeus", "Ziggy"); public Map dogLevels = new HashMap(); @@ -249,6 +250,8 @@ public void loadSettings() this.serverName = config.getString("Settings.ServerName", "Your Server"); this.chatPrefix = config.getString("Settings.ChatPrefix", "MyDog"); this.instantSave = config.getBoolean("Settings.InstantSaveConfig", false); + this.teleportAllTameables = config.getBoolean("Settings.TeleportAllTameables", false); + this.expandedSearch = config.getBoolean("Settings.ExpandedSearch", false); this.randomCollarColor = config.getBoolean("DogSettings.RandomCollarColor", true); this.useLevels = config.getBoolean("DogSettings.UseLevels", true); this.teleportOnWorldChange = config.getBoolean("DogSettings.TeleportOnWorldChange", true); @@ -296,7 +299,7 @@ public void loadSettings() // Messages and sounds this.levelUpSound = config.getString("PlayerInteraction.LevelUpSound", "ENTITY_WOLF_HOWL"); this.levelUpString = config.getString("PlayerInteraction.LevelUpString", "&5&l[{chatPrefix}] &r&5Your dog, {dogNameColor}{dogName}&5, just leveled up to &dLevel {level}&5!"); - this.cannotTeleportWolfString = config.getString("PlayerInteraction.CannotTeleportWolfString", "&c&l[{chatPrefix}] &r&cHello! Looks like you just teleported away from your Dog(s)! " + + this.cannotTeleportTameableString = config.getString("PlayerInteraction.CannotTeleportTameableString", "&c&l[{chatPrefix}] &r&cHello! Looks like you just teleported away from your Pet(s)! " + "They can sadly not find a safe place to stay, so they are staying behind for now :( They will be waiting for you where you left them..."); this.newDogString = config.getString("PlayerInteraction.NewDogString", "&6&l[{chatPrefix}] &r&6Congratulations with your new dog, {dogNameColor}{dogName}&6!"); this.deadDogString = config.getString("PlayerInteraction.DeadDogString", "&c&l[{chatPrefix}] &r&cYour dog, {dogNameColor}{dogName}&c, just passed away... {dogNameColor}{dogName}&c lived for {time}{deadDogLevelString}."); @@ -312,9 +315,11 @@ public void saveSettings() config.set("Settings.Debug", Boolean.valueOf(this.debug)); config.set("Settings.ChatPrefix", this.chatPrefix); config.set("Settings.InstantSaveConfig", Boolean.valueOf(this.instantSave)); + config.set("Settings.ExpandedSearch", Boolean.valueOf(this.expandedSearch)); config.set("DogSettings.RandomCollarColor", this.randomCollarColor); config.set("DogSettings.UseLevels", this.useLevels); config.set("DogSettings.TeleportOnWorldChange", this.teleportOnWorldChange); + config.set("Settings.TeleportAllTameables", this.teleportAllTameables); config.set("DogSettings.OnlyShowNametagOnHover", this.onlyShowNametagOnHover); config.set("DogSettings.AllowPlayerKillExp", this.allowPlayerKillExp); config.set("DogSettings.AllowNametagRename", this.allowNametagRename); @@ -332,7 +337,7 @@ public void saveSettings() // Messages and sounds config.set("PlayerInteraction.LevelUpSound", this.levelUpSound); config.set("PlayerInteraction.LevelUpString", this.levelUpString); - config.set("PlayerInteraction.CannotTeleportWolfString", this.cannotTeleportWolfString); + config.set("PlayerInteraction.CannotTeleportTameableString", this.cannotTeleportTameableString); config.set("PlayerInteraction.NewDogString", this.newDogString); config.set("PlayerInteraction.DeadDogString", this.deadDogString); config.set("PlayerInteraction.DeadDogLevelString", this.deadDogLevelString); diff --git a/src/dk/fido2603/mydog/listeners/WolfMainListener.java b/src/dk/fido2603/mydog/listeners/WolfMainListener.java index 46b7cfe..2fc8029 100644 --- a/src/dk/fido2603/mydog/listeners/WolfMainListener.java +++ b/src/dk/fido2603/mydog/listeners/WolfMainListener.java @@ -16,11 +16,7 @@ import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Sittable; -import org.bukkit.entity.Wolf; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -473,55 +469,61 @@ public void onChunkUnload(ChunkUnloadEvent event) } Location safeLocation = null; - Boolean isSafe = true; Entity[] entities = event.getChunk().getEntities(); for (Entity e : entities) { - if (isSafe && e != null && e.getType().equals(EntityType.WOLF)) + // All tameables + if (e != null && e instanceof Sittable && e instanceof Tameable) { - Wolf dog = (Wolf) e; - if (dog.getOwner() == null || !(dog.getOwner() instanceof Player)) - { - plugin.logDebug("Owner is null or not instance of Player!"); - return; - } - Player player = (Player) dog.getOwner(); - if (MyDog.getDogManager().isDog(dog.getUniqueId()) && player != null && player.isOnline() && (!dog.isSitting() || (!dog.getWorld().equals(player.getWorld()) && plugin.teleportOnWorldChange))) + Tameable tameableEntity = (Tameable) e; + + if (tameableEntity.getOwner() instanceof Player) { - MyDog.getDogManager().getDog(dog.getUniqueId()).saveDogLocation(); - if (MyDog.getPermissionsManager().hasPermission(player, "mydog.teleport")) + Sittable sittingEntity = (Sittable) e; + Player player = (Player) tameableEntity.getOwner(); + + if (player != null && player.isOnline()) { - Location loc = null; - if (safeLocation == null) + // If it's a dog, or if the config allows all tameables to teleport + Boolean isDog = (e.getType().equals(EntityType.WOLF) && MyDog.getDogManager().isDog(tameableEntity.getUniqueId())); + if (isDog || plugin.teleportAllTameables) { - loc = player.getLocation(); - if (!isSafeLocation(loc)) + // If the tameable is sitting, or is in another world + if (!sittingEntity.isSitting() || (!tameableEntity.getWorld().equals(player.getWorld()) && plugin.teleportOnWorldChange)) { - plugin.logDebug("Whoops, seems like our player isn't at a safe location, let's find a good spot for the doggo..."); - loc = searchSafeLocation(loc); - if (loc == null) + // If dog, save location of the dog + if (isDog) { - plugin.logDebug("Did not find a safe place to teleport a wolf! Keeping wolf at unloaded chunks!"); - /*player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + plugin.getChatPrefix() + "] " + ChatColor.RESET + ChatColor.RED + "Hello! Looks like you just teleported away from your Dog(s)! " + - "They can sadly not find a safe place to stay, so they are staying behind for now :( They will be waiting for you where you left them...");*/ - player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.cannotTeleportWolfString)); - isSafe = false; - return; + MyDog.getDogManager().getDog(tameableEntity.getUniqueId()).saveDogLocation(); } - } - } - else - { - loc = safeLocation; - } - plugin.logDebug("It's a safe location, teleporting!"); - plugin.logDebug("Teleported a dog to a player! Chunk-unload!"); - dog.teleport(loc); - if (dog.isSitting()) - { - dog.setSitting(false); + // Begin teleport procedure!! + if (MyDog.getPermissionsManager().hasPermission(player, "mydog.teleport")) + { + Location loc = player.getLocation(); + if (!isSafeLocation(loc) && safeLocation == null) + { + plugin.logDebug("Whoops, seems like our player isn't at a safe location, let's find a good spot for the tameable..."); + loc = searchSafeLocation(loc); + if (loc == null) + { + plugin.logDebug("Did not find a safe place to teleport the tameable! Keeping tameable at unloaded chunks!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.cannotTeleportTameableString)); + return; + } + } + + plugin.logDebug("It's a safe location, teleporting!"); + safeLocation = loc; + plugin.logDebug("Teleported a dog to a player! Chunk-unload!"); + tameableEntity.teleport(safeLocation); + if (sittingEntity.isSitting()) + { + sittingEntity.setSitting(false); + } + } + } } } } @@ -531,19 +533,50 @@ public void onChunkUnload(ChunkUnloadEvent event) public Location searchSafeLocation(Location loc) { - double y; - for (y = 255; y > 1; y--) + if (plugin.expandedSearch) { - loc.setY(y); - plugin.logDebug("Current location = X: " + loc.getX() + " Y: " + loc.getY() + " Z: " + loc.getZ()); - if (isSafeLocation(loc)) + double y; + double x; + double z; + plugin.logDebug("Starting safe location search!"); + for (z = 0; z <= 2; z++) { - plugin.logDebug("Is safe location"); - return loc; + loc.setZ(loc.getZ()+z); + plugin.logDebug("Setting 1 Current location = X: " + loc.getX() + " Y: " + loc.getY() + " Z: " + loc.getZ()); + for (x = 0; x <= 2; x++) + { + loc.setX(loc.getX()+x); + plugin.logDebug("Setting 2 Current location = X: " + loc.getX() + " Y: " + loc.getY() + " Z: " + loc.getZ()); + for (y = 255; y > 1; y--) + { + loc.setY(y); + plugin.logDebug("Setting 3 Current location = X: " + loc.getX() + " Y: " + loc.getY() + " Z: " + loc.getZ()); + if (isSafeLocation(loc)) + { + plugin.logDebug("is safe"); + return loc; + } + plugin.logDebug("not safe"); + } + } } - plugin.logDebug("Not safe location"); } - + else + { + double y; + for (y = 255; y > 1; y--) + { + loc.setY(y); + plugin.logDebug("Current location = X: " + loc.getX() + " Y: " + loc.getY() + " Z: " + loc.getZ()); + if (isSafeLocation(loc)) + { + plugin.logDebug("is safe"); + return loc; + } + plugin.logDebug("not safe"); + } + } + return null; }