Fix the sledge mount's offset

This commit is contained in:
Sam 2017-11-27 16:05:38 +00:00 committed by Alexander Meech
parent 3b1ce13856
commit 593952fa10

View File

@ -1,10 +1,13 @@
package mineplex.core.gadget.gadgets.mount.types; package mineplex.core.gadget.gadgets.mount.types;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,6 +17,9 @@ import org.bukkit.util.Vector;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.GadgetManager;
import mineplex.core.gadget.gadgets.mount.Mount; import mineplex.core.gadget.gadgets.mount.Mount;
@ -39,7 +45,7 @@ public class MountSledge extends Mount<MountSledgeData>
@Override @Override
public MountSledgeData spawnMount(Player player) public MountSledgeData spawnMount(Player player)
{ {
Location location = player.getLocation().subtract(0, 1.5, 0); Location location = player.getLocation().subtract(0, 0.5, 0);
ArmorStand front = player.getWorld().spawn(location, ArmorStand.class); ArmorStand front = player.getWorld().spawn(location, ArmorStand.class);
ArmorStand back = player.getWorld().spawn(location, ArmorStand.class); ArmorStand back = player.getWorld().spawn(location, ArmorStand.class);
@ -62,17 +68,33 @@ public class MountSledge extends Mount<MountSledgeData>
return; return;
} }
Set<Player> toRemove = new HashSet<>();
for (MountSledgeData data : _active.values()) for (MountSledgeData data : _active.values())
{ {
if (data.getOwner().getVehicle() == null)
{
toRemove.add(data.getOwner());
}
ArmorStand front = data.Front; ArmorStand front = data.Front;
ArmorStand back = data.Back; ArmorStand back = data.Back;
Location playerLocation = data.getOwner().getLocation(); Location playerLocation = data.getOwner().getLocation();
playerLocation.setPitch(0); playerLocation.setPitch(0);
Vector direction = playerLocation.getDirection().multiply(0.1); Vector direction = playerLocation.getDirection().multiply(0.5);
front.teleport(front.getLocation().add(direction)); Location newLocation = back.getLocation().add(direction);
back.teleport(back.getLocation().add(direction)); ((CraftEntity) back).getHandle().setPositionRotation(newLocation.getX(), newLocation.getY(), newLocation.getZ(), playerLocation.getYaw(), 0);
newLocation.add(direction.multiply(1.6));
newLocation.setYaw(playerLocation.getYaw());
front.teleport(newLocation);
UtilParticle.PlayParticleToAll(ParticleType.SNOW_SHOVEL, playerLocation, 0.3F, 0, 0.3F, 0.1F, 2, ViewDist.NORMAL);
} }
toRemove.forEach(this::disable);
} }
class MountSledgeData extends MountData class MountSledgeData extends MountData