Fixed thread flood in Vending Machines

This commit is contained in:
Dome 2020-07-07 07:16:58 -04:00 committed by Harmonic
parent a14ff42fe6
commit 15e24f3114

View File

@ -6,8 +6,6 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
@ -17,6 +15,7 @@ import com.eu.habbo.util.pathfinding.Rotation;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
public class InteractionVendingMachine extends InteractionDefault { public class InteractionVendingMachine extends InteractionDefault {
public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException { public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException {
@ -33,12 +32,18 @@ public class InteractionVendingMachine extends InteractionDefault {
public void onClick(GameClient client, Room room, Object[] objects) throws Exception { public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects); super.onClick(client, room, objects);
if (client != null) { if (client == null) {
return;
}
RoomTile tile = this.getRequiredTile(client.getHabbo(), room); RoomTile tile = this.getRequiredTile(client.getHabbo(), room);
if (tile != null) { if (tile != null &&
if (tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
if (this.getExtradata().equals("0") || this.getExtradata().length() == 0) { if (!this.getExtradata().equals("0") || this.getExtradata().length() != 0) {
return;
}
if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) { if (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) && (!client.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || tile.equals(client.getHabbo().getRoomUnit().getGoal()))) {
room.updateHabbo(client.getHabbo()); room.updateHabbo(client.getHabbo());
this.rotateToMachine(client.getHabbo().getRoomUnit()); this.rotateToMachine(client.getHabbo().getRoomUnit());
@ -51,16 +56,7 @@ public class InteractionVendingMachine extends InteractionDefault {
this.setExtradata("1"); this.setExtradata("1");
room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose()); room.scheduledComposers.add(new FloorItemUpdateComposer(this).compose());
Emulator.getThreading().run(() -> { this.runGiveItemThread(client, room);
Emulator.getThreading().run(this, 1000);
this.giveVendingMachineItem(client.getHabbo(), room);
if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
}, 500);
}
} else { } else {
if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) { if (!tile.isWalkable() && tile.state != RoomTileState.SIT && tile.state != RoomTileState.LAY) {
for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { for (RoomTile t : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
@ -84,15 +80,21 @@ public class InteractionVendingMachine extends InteractionDefault {
e.printStackTrace(); e.printStackTrace();
} }
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> client.getHabbo().getRoomUnit().setMoveBlockingTask(Emulator.getThreading().run(() -> {
client.getHabbo().getRoomUnit().setMoveBlockingTask(Emulator.getThreading().run(() -> {
if (client.getHabbo().getRoomUnit().getCurrentLocation().equals(finalTile)) { if (client.getHabbo().getRoomUnit().getCurrentLocation().equals(finalTile)) {
this.rotateToMachine(client.getHabbo().getRoomUnit()); this.rotateToMachine(client.getHabbo().getRoomUnit());
room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose()); room.sendComposer(new RoomUserStatusComposer(client.getHabbo().getRoomUnit()).compose());
} }
this.runGiveItemThread(client, room);
}, 300)), 250);
}, null));
}
}
private void runGiveItemThread(GameClient client, Room room) {
try { try {
Emulator.getThreading().run(() -> { ScheduledFuture thread = Emulator.getThreading().run(() -> {
Emulator.getThreading().run(this, 1000); Emulator.getThreading().run(this, 1000);
this.giveVendingMachineItem(client.getHabbo(), room); this.giveVendingMachineItem(client.getHabbo(), room);
@ -100,16 +102,15 @@ public class InteractionVendingMachine extends InteractionDefault {
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1); room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1);
if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F) if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F)
room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1); room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1);
}, 500).get(); }, 500);
if (thread.isDone()) {
thread.get();
}
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
}, 300));
}, 250);
}, null));
}
}
}
} }
@Override @Override