From 40793258b6b3cb9eff9521bcefa992b313438713 Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Mon, 30 Aug 2021 15:46:15 +0200 Subject: [PATCH] Custom configs added for wired (multiple users teleporting at the same time) Custom place/rotate under user setting Custom walk on furni if placed/rotated under user setting --- .../items/interactions/InteractionWired.java | 36 ++++++++++++++++-- .../com/eu/habbo/habbohotel/rooms/Room.java | 38 +++++++++++++++---- .../habbo/habbohotel/wired/WiredHandler.java | 9 +++-- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java index c19b1ec9..8a8f1e7f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java @@ -4,9 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer; +import gnu.trove.map.hash.TLongLongHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +18,7 @@ import java.sql.SQLException; public abstract class InteractionWired extends InteractionDefault { private static final Logger LOGGER = LoggerFactory.getLogger(InteractionWired.class); private long cooldown; + private TLongLongHashMap userExecutionCache = new TLongLongHashMap(3); InteractionWired(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -69,10 +70,16 @@ public abstract class InteractionWired extends InteractionDefault { public abstract void onPickUp(); public void activateBox(Room room) { - this.setExtradata(this.getExtradata().equals("1") ? "0" : "1"); - room.sendComposer(new ItemStateComposer(this).compose()); + this.activateBox(room, (RoomUnit)null, 0L); } + public void activateBox(Room room, RoomUnit roomUnit, long millis) { + this.setExtradata(this.getExtradata().equals("1") ? "0" : "1"); + room.sendComposer(new ItemStateComposer(this).compose()); + if (roomUnit != null) { + this.addUserExecutionCache(roomUnit.getId(), millis); + } + } protected long requiredCooldown() { return 50L; @@ -96,4 +103,27 @@ public abstract class InteractionWired extends InteractionDefault { public boolean isUsable() { return true; } + + public boolean userCanExecute(int roomUnitId, long timestamp) { + if (roomUnitId == -1) { + return true; + } else { + if (this.userExecutionCache.containsKey((long)roomUnitId)) { + long lastTimestamp = this.userExecutionCache.get((long)roomUnitId); + if (timestamp - lastTimestamp < 100L) { + return false; + } + } + + return true; + } + } + + public void clearUserExecutionCache() { + this.userExecutionCache.clear(); + } + + public void addUserExecutionCache(int roomUnitId, long timestamp) { + this.userExecutionCache.put((long)roomUnitId, timestamp); + } } 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 58321d7d..18c6cdcb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4501,9 +4501,11 @@ public class Room implements Comparable, ISerialize, Runnable { THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); for (RoomTile t : occupiedTiles) { if(t.state == RoomTileState.INVALID) return FurnitureMovementError.INVALID_MOVE; - if (checkForUnits && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; - if (checkForUnits && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; - if (checkForUnits && this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + if(!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) { + if (checkForUnits && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; + if (checkForUnits && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; + if (checkForUnits && this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + } } List>> tileFurniList = new ArrayList<>(); @@ -4610,10 +4612,14 @@ public class Room implements Comparable, ISerialize, Runnable { } public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor) { - return moveFurniTo(item, tile, rotation, actor, true); + return moveFurniTo(item, tile, rotation, actor, true, true); } public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor, boolean sendUpdates) { + return moveFurniTo(item, tile, rotation, actor, sendUpdates, true); + } + + public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor, boolean sendUpdates, boolean checkForUnits) { RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY()); boolean pluginHelper = false; @@ -4631,6 +4637,7 @@ public class Room implements Comparable, ISerialize, Runnable { //Check if can be placed at new position THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); + THashSet newOccupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); HabboItem topItem = this.getTopItemAt(occupiedTiles, null); @@ -4640,9 +4647,14 @@ public class Room implements Comparable, ISerialize, Runnable { HabboItem tileTopItem = this.getTopItemAt(t.x, t.y); if (!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack()) : this.calculateTileState(t, item).equals(RoomTileState.INVALID)))) return FurnitureMovementError.CANT_STACK; - if (!magicTile && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; - if (!magicTile && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; - if (!magicTile && this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + + if(!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) { + if (checkForUnits) { + if (!magicTile && this.hasHabbosAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_HABBOS; + if (!magicTile && this.hasBotsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_BOTS; + if (!magicTile && this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; + } + } } } @@ -4746,6 +4758,18 @@ public class Room implements Comparable, ISerialize, Runnable { ); this.updateBotsAt(t.x, t.y); } + if(Emulator.getConfig().getBoolean("wired.place.under", false)) { + for(RoomTile t : newOccupiedTiles) { + for(Habbo h : this.getHabbosAt(t.x, t.y)) { + try { + item.onWalkOn(h.getRoomUnit(), this, null); + } + catch(Exception e) { + + } + } + } + } return FurnitureMovementError.NONE; } diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index 9f27ad78..2cbc6d09 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -160,8 +160,9 @@ public class WiredHandler { public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff, final THashSet effectsToExecute) { long millis = System.currentTimeMillis(); - if (Emulator.isReady && trigger.canExecute(millis) && trigger.execute(roomUnit, room, stuff)) { - trigger.activateBox(room); + int roomUnitId = roomUnit != null ? roomUnit.getId() : -1; + if (Emulator.isReady && ((Emulator.getConfig().getBoolean("wired.custom.enabled", false) && (trigger.canExecute(millis) || roomUnitId > -1) && trigger.userCanExecute(roomUnitId, millis)) || (!Emulator.getConfig().getBoolean("wired.custom.enabled", false) && trigger.canExecute(millis))) && trigger.execute(roomUnit, room, stuff)) { + trigger.activateBox(room, roomUnit, millis); THashSet conditions = room.getRoomSpecialTypes().getConditions(trigger.getX(), trigger.getY()); THashSet effects = room.getRoomSpecialTypes().getEffects(trigger.getX(), trigger.getY()); @@ -193,7 +194,7 @@ public class WiredHandler { THashSet extras = room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY()); for (InteractionWiredExtra extra : extras) { - extra.activateBox(room); + extra.activateBox(room, roomUnit, millis); } List effectList = new ArrayList<>(effects); @@ -241,7 +242,7 @@ public class WiredHandler { LOGGER.error("Caught exception", e); } - effect.activateBox(room); + effect.activateBox(room, roomUnit, millis); } }, effect.getDelay() * 500); }