From 9ed3bfc37a85afff47d9c54bc909f8268e4c84e5 Mon Sep 17 00:00:00 2001 From: Stankman Date: Tue, 20 Jun 2023 22:01:21 -0500 Subject: [PATCH] Fixed Some Wireds with new structure, patched bug with repeaters, loadWired moved to Items --- .../habbo/habbohotel/items/ItemManager.java | 8 ++++- .../WiredEffectChangeFurniDirection.java | 13 ++------ .../wired/triggers/WiredTriggerRepeater.java | 30 +++++++++++++++++ .../triggers/WiredTriggerRepeaterLong.java | 32 ++++++++++++++++++- .../com/eu/habbo/habbohotel/rooms/Room.java | 7 ++-- .../eu/habbo/habbohotel/rooms/RoomState.java | 12 +++---- .../rooms/GetGuestRoomResultComposer.java | 2 +- .../rooms/RoomSettingsDataComposer.java | 2 +- 8 files changed, 82 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java index f798e0fe..47eaadf1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -685,7 +685,13 @@ public class ItemManager { Constructor c = itemClass.getConstructor(ResultSet.class, Item.class); c.setAccessible(true); - return (HabboItem) c.newInstance(set, baseItem); + HabboItem item = (HabboItem) c.newInstance(set, baseItem); + + if (item instanceof InteractionWired interactionWired) { + interactionWired.loadWiredSettings(set); + } + + return item; } catch (Exception e) { log.error("Caught exception", e); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index 1fa147ee..19e5d6cc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -76,16 +76,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { } for(HabboItem item : this.getWiredSettings().getItems(room)) { - WiredChangeDirectionSetting setting = null; - if(!this.itemsSettings.containsKey(item)) { - this.itemsSettings.put(item, new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startDirection)); - } else { - setting = this.itemsSettings.get(item); - } - - if(setting == null) { - continue; - } + WiredChangeDirectionSetting setting = this.itemsSettings.computeIfAbsent(item, k -> + new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startDirection) + ); RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue()); int count = 1; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java index 6a298bfd..f9ccd607 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -38,8 +39,37 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy } } + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + if(room.getTriggersOnRoom().containsValue(this)) { + room.getTriggersOnRoom().remove(oldLocation.getX() + ";" + oldLocation.getY()); + } + + super.onMove(room, oldLocation, newLocation); + } + + @Override + public void onPickUp(Room room) { + if(room.getTriggersOnRoom().containsValue(this)) { + room.getTriggersOnRoom().remove(this.getX() + ";" + this.getY()); + } + + super.onPickUp(room); + } + @Override public void cycle(Room room) { + String key = this.getX() + ";" + this.getY(); + + if(room.getTriggersOnRoom().containsKey(key)) { + if(room.getTriggersOnRoom().get(key).getId() != this.getId()) { + if(!(room.getTriggersOnRoom().get(key) instanceof WiredTriggerRepeaterLong) && room.getTriggersOnRoom().get(key).getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) <= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) { + return; + } + } + } + room.getTriggersOnRoom().put(key, this); + this.counter += 500; if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500) { this.counter = 0; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java index e61a170c..85b7a7d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -37,10 +38,39 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements } } + @Override + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + if(room.getTriggersOnRoom().containsValue(this)) { + room.getTriggersOnRoom().remove(oldLocation.getX() + ";" + oldLocation.getY()); + } + + super.onMove(room, oldLocation, newLocation); + } + + @Override + public void onPickUp(Room room) { + if(room.getTriggersOnRoom().containsValue(this)) { + room.getTriggersOnRoom().remove(this.getX() + ";" + this.getY()); + } + + super.onPickUp(room); + } + @Override public void cycle(Room room) { + String key = this.getX() + ";" + this.getY(); + + if(room.getTriggersOnRoom().containsKey(key)) { + if(room.getTriggersOnRoom().get(key).getId() != this.getId()) { + if(room.getTriggersOnRoom().get(key).getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) <= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) { + return; + } + } + } + room.getTriggersOnRoom().put(key, this); + this.counter += 500; - if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME)) { + if (this.counter >= this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 5000) { this.counter = 0; if (this.getRoomId() != 0) { if (room.isLoaded()) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 8f9824f7..c340743e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -292,6 +292,8 @@ public class Room implements Comparable, ISerialize, Runnable { private RoomSpecialTypes roomSpecialTypes; @Getter private TraxManager traxManager; + @Getter + private HashMap triggersOnRoom; private boolean cycleOdd; @Getter private long cycleTimestamp; @@ -381,6 +383,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.activeTrades = new THashSet<>(0); this.rights = new TIntArrayList(); this.userVotes = new ArrayList<>(); + this.triggersOnRoom = new HashMap<>(); } public synchronized void loadData() { @@ -407,7 +410,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.loadBots(connection); this.loadPets(connection); this.loadWordFilter(connection); - this.loadWiredData(connection); +// this.loadWiredData(connection); this.idleCycles = 0; this.loaded = true; @@ -1027,7 +1030,7 @@ public class Room implements Comparable, ISerialize, Runnable { message.appendInt(this.ownerId); message.appendString(this.ownerName); } - message.appendInt(this.state.getState()); + message.appendInt(this.state.ordinal()); message.appendInt(this.getUserCount()); message.appendInt(this.usersMax); message.appendString(this.description); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java index eda3e0b5..b7f0a7d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java @@ -6,12 +6,8 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum RoomState { - OPEN(0), - LOCKED(1), - PASSWORD(2), - INVISIBLE(3); - - private final int state; - - + OPEN, + LOCKED, + PASSWORD, + INVISIBLE } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java index 24f06ade..0f37d218 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java @@ -29,7 +29,7 @@ public class GetGuestRoomResultComposer extends MessageComposer { this.response.appendInt(this.room.getOwnerId()); this.response.appendString(this.room.getOwnerName()); } - this.response.appendInt(this.room.getState().getState()); + this.response.appendInt(this.room.getState().ordinal()); this.response.appendInt(this.room.getUserCount()); this.response.appendInt(this.room.getUsersMax()); this.response.appendString(this.room.getDescription()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java index 6520ae16..6e461e65 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java @@ -15,7 +15,7 @@ public class RoomSettingsDataComposer extends MessageComposer { this.response.appendInt(this.room.getId()); this.response.appendString(this.room.getName()); this.response.appendString(this.room.getDescription()); - this.response.appendInt(this.room.getState().getState()); + this.response.appendInt(this.room.getState().ordinal()); this.response.appendInt(this.room.getCategory()); this.response.appendInt(this.room.getUsersMax()); this.response.appendInt(this.room.getUsersMax());