Skip to content

Commit

Permalink
Adding entity tracking to console
Browse files Browse the repository at this point in the history
Adds in an [Entity-#] tag to the console debug messages to identify which entity is being tracked by that message.
  • Loading branch information
CoolLord22 committed Mar 30, 2023
1 parent d9a837b commit d82f258
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/coollord22/otheranimalteleport/OATMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public static void teleportLeashedEnt(Entity ent, Location from, Location to, Pl
if(plugin.toUseTickets)
fromChunk.addPluginChunkTicket(plugin);

plugin.log.logInfo("Attempting to null the leash holder.", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Attempting to null the leash holder.", Verbosity.HIGHEST);
((LivingEntity) ent).setLeashHolder(null);

boolean invulnerable = ent.isInvulnerable();

new BukkitRunnable() {
@Override
public void run() {
plugin.log.logInfo("Protecting entity with invulnerability and resistance.", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Protecting entity with invulnerability and resistance.", Verbosity.HIGHEST);
ent.setInvulnerable(true);
((LivingEntity) ent).addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 40, 5));

plugin.log.logInfo("Teleporting entity " + ent.getType() + " with ID: " + ent.getEntityId(), Verbosity.HIGH);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Teleporting entity " + ent.getType(), Verbosity.HIGH);
ent.teleport(to);

plugin.log.logInfo("Re-attaching leash holder as " + p.getName() + ".", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Re-attaching leash holder as " + p.getName() + ".", Verbosity.HIGHEST);
((LivingEntity) ent).setLeashHolder(p);

if(plugin.toUseTickets)
Expand All @@ -53,11 +53,11 @@ public static void teleportEnt(Entity ent, Location from, Location to, Player p,
new BukkitRunnable() {
@Override
public void run() {
plugin.log.logInfo("Protecting entity with invulnerability and resistance.", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Protecting entity with invulnerability and resistance.", Verbosity.HIGHEST);
ent.setInvulnerable(true);
((LivingEntity) ent).addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 40, 5));

plugin.log.logInfo("Teleporting entity" + ent.getType() + " with ID: " + ent.getEntityId(), Verbosity.HIGH);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Teleporting entity" + ent.getType(), Verbosity.HIGH);
ent.teleport(to);

if(plugin.toUseTickets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ public void onTeleport(PlayerTeleportEvent event) {
boolean toSendLeft = false;

for(Entity ent : event.getFrom().getWorld().getNearbyEntities(event.getFrom(), radius, radius, radius)) {
plugin.log.logInfo("Found an entity to teleport: " + ent.getType() + " . Checking if it is allowed.", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Found a(n) " + ent.getType() + ". Checking if type is allowed.", Verbosity.HIGHEST);
if(plugin.config.allowedEnts.contains(ent.getType())) {
plugin.log.logInfo("Entity check passed, seeing if player has leashed permissions.", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Entity-type check passed, checking player permissions.", Verbosity.HIGHEST);
if(ent instanceof LivingEntity && event.getPlayer().hasPermission("otheranimalteleport.player.teleportleashed")) {
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Player leashed permissions check passed, checking leash owner.", Verbosity.HIGHEST);
if(((LivingEntity) ent).isLeashed() && ((LivingEntity) ent).getLeashHolder().equals(event.getPlayer())) {
try {
plugin.log.logInfo("Attempting to send leashed entity: " + ent.getType() + ".", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Leash owner passed. Attempting to teleport entity.", Verbosity.HIGHEST);
OATMethods.teleportLeashedEnt(ent, event.getFrom(), event.getTo(), event.getPlayer(), plugin);
continue;
} catch(Exception e) {
Expand All @@ -82,10 +83,11 @@ public void onTeleport(PlayerTeleportEvent event) {
toSendLeft = true;
}
if(ent instanceof Tameable && event.getPlayer().hasPermission("otheranimalteleport.player.teleportpets")) {
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Player pet permissions check passed, checking pet owner.", Verbosity.HIGHEST);
if(((Tameable) ent).isTamed() && ((Tameable) ent).getOwner() != null && ((Tameable) ent).getOwner().equals(event.getPlayer())) {
if(ent instanceof Sittable && !((Sittable) ent).isSitting()) {
try {
plugin.log.logInfo("Attempting to send pet entity: " + ent.getType() + ".", Verbosity.HIGHEST);
plugin.log.logInfo("[Ent-" + ent.getEntityId() + "] Pet checks passed. Attempting to teleport entity.", Verbosity.HIGHEST);
OATMethods.teleportEnt(ent, event.getFrom(), event.getTo(), event.getPlayer(), plugin);
continue;
} catch(Exception e) {
Expand Down

0 comments on commit d82f258

Please sign in to comment.