I have a travel plugin which is i cant quite figure out why it wouldnt work on second travel. I would appreciate any help given. It is a simple teleport class that throws the player up into the air before teleporting. Whilst teleporting the player cant move left or right etc It works but the problem is after travel on second attempt it wont change the players velocity Again i would appreciate any help --------------- The classes -------------- Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Travel.java Code: public class Travel { private Player player; private Location location; private Location from; private Sound sound; private String name; private State state; private List<Effect> effects = new ArrayList<Effect>(); private static Plugin plugin; public static void setPlugin(Plugin p){ plugin = p; } public Travel(){} public Travel(Player player, Location location, Sound sound){ this(player, location, sound, null); } public Travel(Player player, Location location, Sound sound, List<Effect> e){ this.state = State.NOT_STARTED; this.player = player; this.location = location; this.from = player.getLocation(); if (e != null && !e.isEmpty()) this.effects = e; this.sound = sound; this.name = player.getDisplayName() + " to " + location.getWorld().getName(); } public String getName() { return this.name; } public void setPlayer(Player player){ this.player = player; } public void addEffect(Effect effect){ this.effects.add(effect); } /*deprecated*/ public void initialize() { this.state = State.STARTED; Vector v = new Vector(0, 1.5, 0); player.setVelocity(v); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { state = State.IN_PROCESS; player.teleport(location); player.playSound(location, sound, 6, 1); for (Effect e : effects) player.playEffect(location, e, 100); state = State.FINISHED; } }, 30L); } public List<Effect> getEffects(){ return this.effects; } public Location getLocation(){ return this.location; } public Location getFrom() { return this.from; } public State getState() { return this.state; } public Player getPlayer(){ return this.player; } } Travels.java Code:java public class Travels implements Listener{ private static Map<Player, Travel> travelers = new HashMap<>(); public static Travel travel(Player player, Location to, Sound sound){ Travel t = new Travel(player, to, sound); travelers.put(player, t); return t; } @EventHandler public void onFallDamage(EntityDamageEvent e){ if (!(e.getEntity() instanceof Player)) return; Player p = (Player) e.getEntity(); if (travelers.containsKey(p)){ if (travelers.get(p).getState() == State.FINISHED) { travelers.remove(p); return; } e.setCancelled(true); } } @EventHandler public void onMove(PlayerMoveEvent e){ if (travelers.containsKey(e.getPlayer())){ if (travelers.get(e.getPlayer()).getState() == State.FINISHED) { travelers.remove(e.getPlayer()); return; } Location to = e.getTo(); Location from = travelers.get(e.getPlayer()).getFrom(); Location p = e.getPlayer().getLocation(); Travel t = travelers.get(e.getPlayer()); if (to.getX() != from.getX() || to.getZ() != from.getZ()){ t.getPlayer().teleport(new Location(p.getWorld(), p.getX(), p.getY() ,p.getZ())); } if (to.getY() < e.getPlayer().getLocation().getY()){ e.setCancelled(true); } } } @EventHandler public void onTeleport(PlayerTeleportEvent e){ if (travelers.containsKey(e.getPlayer())){ Player p = e.getPlayer(); if (travelers.get(p).getState() == State.FINISHED){ travelers.remove(p); return; } e.setCancelled(true); } } } State enum Code: public enum State { FINISHED, STARTED, NOT_STARTED, IN_PROCESS } Those are the three classes involved And i would start it like this Example Code: Travel travel = Travels.travel(p, t.getLocation(), Sound.FIREWORK_BLAST);travel.initialize(); travel.initialize(); Thanks for the help
I don't have much time till I have to leave so I can't help with your error but I just noticed you're storing a Player in a Map. Please don't do that, I don't care whether you've handled it safely, just don't. Store the UUID of the Player instead, and change everything to getPlayer().getUniqueId() instead.
@MajorSkillage I have three to be precise. They do different things. I can do Trade(player, tolocation, sound, <optional> effects)
You could always check the arguments and depending on the arguments of the command makes it depend on what happens. Play around with the velocity instantly after the command is run such as /travel (user) (location) then save the Location as another object and set the velocity however there could be another argument to test the velocity you need/want. It could be a different velocity depending on the location, il admit I am not too good with velocity this is just a guess to me.
@MajorSkillage The teleportation part works well the problem is just on the second go (lets say i just 'traveled') it doesnt properly throw the player up in the air. My guess is that the player isnt removed from the map fast enough, but i dont think thats it