diff --git a/src/main/java/lee/code/pets/lang/Lang.java b/src/main/java/lee/code/pets/lang/Lang.java index b91e2d9..c451046 100644 --- a/src/main/java/lee/code/pets/lang/Lang.java +++ b/src/main/java/lee/code/pets/lang/Lang.java @@ -38,7 +38,7 @@ public enum Lang { ERROR_NOT_CONSOLE_COMMAND("&cThis command does not work in console."), ERROR_RENAME_BLANK("&cThe pet name input was blank, please pick a pet name using normal letters and numbers."), ERROR_ENTITY_NOT_SUPPORTED("&cThe entity {0} is not a supported pet type!"), - ERROR_RIDE_PROTECTED_REGION("&cYou can't mount your pet while inside a protected spawn region."), + ERROR_RIDE_PROTECTED_REGION("&cYou can't ride your pet while inside a protected spawn region."), ; @Getter private final String string; diff --git a/src/main/java/lee/code/pets/listeners/PetListener.java b/src/main/java/lee/code/pets/listeners/PetListener.java index 68fad19..f6f0d3c 100644 --- a/src/main/java/lee/code/pets/listeners/PetListener.java +++ b/src/main/java/lee/code/pets/listeners/PetListener.java @@ -1,5 +1,6 @@ package lee.code.pets.listeners; +import io.papermc.paper.event.entity.EntityMoveEvent; import lee.code.hooks.Hooks; import lee.code.pets.Pets; import lee.code.pets.enums.PettingSound; @@ -164,4 +165,16 @@ public void onEntityPortal(EntityPortalEvent e) { if (e.isCancelled()) return; if (pets.getPetManager().isPet(e.getEntity())) e.setCancelled(true); } + + @EventHandler + public void onPetMoveIntoProtectedRegion(EntityMoveEvent e) { + if (!pets.getPetManager().isPet(e.getEntity())) return; + if (e.getEntity().getPassengers().isEmpty()) return; + for (Entity passenger : e.getEntity().getPassengers()) { + if (passenger instanceof Player player && Hooks.isLocationProtected(player)) { + e.getEntity().removePassenger(passenger); + player.sendMessage(Lang.PREFIX.getComponent(null).append(Lang.ERROR_RIDE_PROTECTED_REGION.getComponent(null))); + } + } + } }