-
-
Notifications
You must be signed in to change notification settings - Fork 406
Teleport pets with player #7400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||
| package com.palmergames.bukkit.towny.utils; | ||||||||||
|
|
||||||||||
| import java.util.ArrayList; | ||||||||||
| import java.util.List; | ||||||||||
| import java.util.Locale; | ||||||||||
| import java.util.Objects; | ||||||||||
|
|
@@ -19,7 +20,11 @@ | |||||||||
| import io.papermc.lib.PaperLib; | ||||||||||
| import org.bukkit.Bukkit; | ||||||||||
| import org.bukkit.Location; | ||||||||||
| import org.bukkit.entity.AnimalTamer; | ||||||||||
| import org.bukkit.entity.Entity; | ||||||||||
| import org.bukkit.entity.Player; | ||||||||||
| import org.bukkit.entity.Sittable; | ||||||||||
| import org.bukkit.entity.Tameable; | ||||||||||
| import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; | ||||||||||
|
|
||||||||||
| import com.palmergames.bukkit.towny.Towny; | ||||||||||
|
|
@@ -669,12 +674,52 @@ private static void initiateSpawn(Player player, Location spawnLoc, int cooldown | |||||||||
| // Don't use teleport warmup | ||||||||||
| if (player.getVehicle() != null) | ||||||||||
| player.getVehicle().eject(); | ||||||||||
| PaperLib.teleportAsync(player, spawnLoc, TeleportCause.COMMAND); | ||||||||||
|
|
||||||||||
| List<Entity> pets = getPets(player); | ||||||||||
| pets.add(player); | ||||||||||
| teleportEntities(spawnLoc, pets, TeleportCause.COMMAND); | ||||||||||
| if (cooldown > 0 && !hasPerm(player, PermissionNodes.TOWNY_SPAWN_ADMIN_NOCOOLDOWN)) | ||||||||||
| CooldownTimerTask.addCooldownTimer(player.getName(), "teleport", cooldown); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Gets any pets owned by the specified player that are nearby them | ||||||||||
| * | ||||||||||
| * @param player The player to get the pets of | ||||||||||
| */ | ||||||||||
| public static List<Entity> getPets(Player player) { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| List<Entity> pets = new ArrayList<>(); | ||||||||||
|
|
||||||||||
| for (Entity entity : player.getNearbyEntities(16, 16, 16)) { | ||||||||||
| if (!(entity instanceof Tameable tameable)) continue; | ||||||||||
|
|
||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method doesn't seem to exist
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking at the paper javadocs, but the same method exists on World on spigot |
||||||||||
| AnimalTamer tamer = tameable.getOwner(); | ||||||||||
| if (tamer == null) continue; | ||||||||||
|
|
||||||||||
| if (!(entity instanceof Sittable sittable)) continue; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about non sittable pets? When #6865 is merged the types of entities that are teleported could be made configurable
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what pets are non-sittable that also follow you like a dog or cat
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or do you mean for adding things like horses, camels etc. if that's the case i could change it to check if they are currently riding something |
||||||||||
| if (sittable.isSitting()) continue; | ||||||||||
|
|
||||||||||
| if (tamer.equals(player)) | ||||||||||
| pets.add(entity); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return pets; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Teleports all specified entities to the specified location | ||||||||||
| * | ||||||||||
| * @param loc Location to teleport to | ||||||||||
| * @param entities Entities to teleport | ||||||||||
| * @param cause What caused the teleport | ||||||||||
| */ | ||||||||||
| public static void teleportEntities(Location loc, List<Entity> entities, TeleportCause cause) { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| for (Entity entity : entities) { | ||||||||||
| PaperLib.teleportAsync(entity, loc, cause); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Begin a costed teleportation. | ||||||||||
| * | ||||||||||
|
|
@@ -745,8 +790,11 @@ private static void initiatePluginTeleport(Resident resident, Location loc, bool | |||||||||
| final Player player = resident.getPlayer(); | ||||||||||
| if (player == null) | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| List<Entity> pets = getPets(player); | ||||||||||
| pets.add(player); | ||||||||||
|
|
||||||||||
| plugin.getScheduler().runLater(player, () -> PaperLib.teleportAsync(resident.getPlayer(), loc, TeleportCause.PLUGIN), | ||||||||||
| plugin.getScheduler().runLater(player, () -> teleportEntities(loc, pets, TeleportCause.PLUGIN), | ||||||||||
| ignoreWarmup ? 0 : TownySettings.getTeleportWarmupTime() * 20L); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to call it entities since the player is added to it (and is not a pet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Came here to say this.