Skip to content

Commit

Permalink
Teleports fixed + cleanup
Browse files Browse the repository at this point in the history
Fixed:
- Teleports now work for long distances

Cleaned:
- Removed some unnecessary code in teleport logic
- Will just look for fall damage instead of fall damage and downward velocity in saveFly()
  • Loading branch information
Jakllp committed Mar 29, 2021
1 parent 3b74e83 commit 4bd9f9e
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/main/java/com/useful/ucars/uCarsListener.java
Expand Up @@ -1086,11 +1086,6 @@ else if (fuelEnabled
if (s != null) {
String[] lines = s.getLines();
if (lines[0].equalsIgnoreCase("[Teleport]")) {
Boolean raceCar = false;
if (car.hasMetadata("kart.racing")
|| UEntityMeta.hasMetadata(car, "kart.racing")) {
raceCar = true;
}
UEntityMeta.setMetadata(car, "safeExit.ignore", new StatValue(null, plugin));

String xs = lines[1];
Expand Down Expand Up @@ -1133,17 +1128,13 @@ else if (fuelEnabled

UUID carId = car.getUniqueId();

Location toTele = new Location(s.getWorld(), x,
final Location toTele = new Location(s.getWorld(), x,
y, z);
Chunk ch = toTele.getChunk();
if (ch.isLoaded()) {
if (!ch.isLoaded()) {
ch.load(true);
}
car.teleport(toTele);
UEntityMeta.setMetadata(car, "carhealth", health);
if (raceCar) {
UEntityMeta.setMetadata(car, "kart.racing", new StatValue(null, plugin));
}
player.teleport(toTele.clone().add(0,2,0));
uCarRespawnEvent evnt = new uCarRespawnEvent(car, carId, car.getUniqueId(),
CarRespawnReason.TELEPORT);
plugin.getServer().getPluginManager().callEvent(evnt);
Expand All @@ -1156,6 +1147,7 @@ else if (fuelEnabled
Bukkit.getScheduler().runTaskLater(plugin, new Runnable(){
@Override
public void run() {
ucar.teleport(toTele);
ucar.addPassenger(player); //For the sake of uCarsTrade
return;
}}, 2l);
Expand Down Expand Up @@ -1286,10 +1278,10 @@ void safeFly(EntityDamageEvent event) {
}
Player p = (Player) event.getEntity();
if (inACar(p.getName())) {
Vector vel = p.getVehicle().getVelocity();
event.setCancelled(true);
/*Vector vel = p.getVehicle().getVelocity();
if (!(vel.getY() > -0.1 && vel.getY() < 0.1)) {
event.setCancelled(true);
} /*else {
} else {
try {
p.damage(event.getDamage());
} catch (Exception e) {
Expand Down

0 comments on commit 4bd9f9e

Please sign in to comment.