Use specific dependencies in SimpleSafeTTeleporter.

This commit is contained in:
Jeremy Wood 2023-03-07 19:00:06 -05:00
parent 160f49bbae
commit 177adf80cb
No known key found for this signature in database
GPG Key ID: C5BAD04C77B91B4B

View File

@ -10,7 +10,9 @@ package com.onarandombox.MultiverseCore.teleportation;
import co.aikar.commands.BukkitCommandIssuer;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.DestinationInstance;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
import jakarta.inject.Inject;
@ -32,11 +34,19 @@ import org.jvnet.hk2.annotations.Service;
*/
@Service
public class SimpleSafeTTeleporter implements SafeTTeleporter {
private MultiverseCore plugin;
private final MultiverseCore plugin;
private final LocationManipulation locationManipulation;
private final BlockSafety blockSafety;
@Inject
public SimpleSafeTTeleporter(MultiverseCore plugin) {
public SimpleSafeTTeleporter(
MultiverseCore plugin,
LocationManipulation locationManipulation,
BlockSafety blockSafety
) {
this.plugin = plugin;
this.locationManipulation = locationManipulation;
this.blockSafety = blockSafety;
}
private static final Vector DEFAULT_VECTOR = new Vector();
@ -62,7 +72,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
if (safe != null) {
safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
Logging.fine("Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe));
Logging.fine("Hey! I found one: " + locationManipulation.strCoordsRaw(safe));
} else {
Logging.fine("Uh oh! No safe place found!");
}
@ -76,7 +86,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
}
// We want half of it, so we can go up and down
tolerance /= 2;
Logging.finer("Given Location of: " + plugin.getLocationManipulation().strCoordsRaw(l));
Logging.finer("Given Location of: " + locationManipulation.strCoordsRaw(l));
Logging.finer("Checking +-" + tolerance + " with a radius of " + radius);
// For now this will just do a straight up block.
@ -144,13 +154,13 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
// ...
int adjustedCircle = ((circle - 1) / 2);
checkLoc.add(adjustedCircle, 0, 0);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
// Now we go to the right that adjustedCircle many
for (int i = 0; i < adjustedCircle; i++) {
checkLoc.add(0, 0, 1);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
}
@ -158,7 +168,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
// Then down adjustedCircle *2
for (int i = 0; i < adjustedCircle * 2; i++) {
checkLoc.add(-1, 0, 0);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
}
@ -166,7 +176,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
// Then left adjustedCircle *2
for (int i = 0; i < adjustedCircle * 2; i++) {
checkLoc.add(0, 0, -1);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
}
@ -174,7 +184,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
// Then up Then left adjustedCircle *2
for (int i = 0; i < adjustedCircle * 2; i++) {
checkLoc.add(1, 0, 0);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
}
@ -182,7 +192,7 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
// Then finish up by doing adjustedCircle - 1
for (int i = 0; i < adjustedCircle - 1; i++) {
checkLoc.add(0, 0, 1);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(checkLoc)) {
if (blockSafety.playerCanSpawnHereSafely(checkLoc)) {
return true;
}
}
@ -255,25 +265,25 @@ public class SimpleSafeTTeleporter implements SafeTTeleporter {
@Override
public Location getSafeLocation(Entity entity, DestinationInstance destination) {
Location l = destination.getLocation(entity);
if (plugin.getBlockSafety().playerCanSpawnHereSafely(l)) {
if (blockSafety.playerCanSpawnHereSafely(l)) {
Logging.fine("The first location you gave me was safe.");
return l;
}
if (entity instanceof Minecart) {
Minecart m = (Minecart) entity;
if (!plugin.getBlockSafety().canSpawnCartSafely(m)) {
if (!blockSafety.canSpawnCartSafely(m)) {
return null;
}
} else if (entity instanceof Vehicle) {
Vehicle v = (Vehicle) entity;
if (!plugin.getBlockSafety().canSpawnVehicleSafely(v)) {
if (!blockSafety.canSpawnVehicleSafely(v)) {
return null;
}
}
Location safeLocation = this.getSafeLocation(l);
if (safeLocation != null) {
// Add offset to account for a vehicle on dry land!
if (entity instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) {
if (entity instanceof Minecart && !blockSafety.isEntitiyOnTrack(safeLocation)) {
safeLocation.setY(safeLocation.getBlockY() + .5);
Logging.finer("Player was inside a minecart. Offsetting Y location.");
}