Skip to content

Commit

Permalink
Remove players from pet when in protected region
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Mar 18, 2024
1 parent a57ec97 commit 2cc94ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/lee/code/pets/lang/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/lee/code/pets/listeners/PetListener.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)));
}
}
}
}

0 comments on commit 2cc94ed

Please sign in to comment.