diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index d32e932a..918f12fb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -96,8 +96,13 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { List tasks = new ArrayList<>(); tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId)); tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); + Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, null)); + + List failedReach = new ArrayList<>(); + failedReach.add(() -> tasks.forEach(Runnable::run)); + + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach)); } return true; diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index e8ef0c71..296490e7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -47,9 +47,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable { if (this.goalTile == null) return; - if (this.walker.getGoal().equals(this.goalTile)) //Check if the goal is still the same. Chances are something is running the same task. If so we dump this task. - { - //Check if arrived. + if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for (Runnable r : this.targetReached) { Emulator.getThreading().run(r); @@ -57,17 +55,6 @@ public class RoomUnitWalkToRoomUnit implements Runnable { WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{this.walker}); } } else { - List tiles = this.room.getLayout().getTilesAround(this.target.getCurrentLocation()); - - for (RoomTile t : tiles) { - if (t.equals(this.goalTile)) { - Emulator.getThreading().run(this, 500); - return; - } - } - - this.findNewLocation(); - Emulator.getThreading().run(this, 500); } } @@ -76,8 +63,15 @@ public class RoomUnitWalkToRoomUnit implements Runnable { private void findNewLocation() { this.goalTile = this.walker.getClosestAdjacentTile(this.target.getCurrentLocation().x, this.target.getCurrentLocation().y, true); - if (this.goalTile == null) + if (this.goalTile == null) { + if (this.failedReached != null) { + for (Runnable r : this.failedReached) { + Emulator.getThreading().run(r); + } + } + return; + } this.walker.setGoalLocation(this.goalTile);