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
This commit is contained in:
ArpyAge 2021-08-30 15:46:15 +02:00
parent be3207eca0
commit 40793258b6
3 changed files with 69 additions and 14 deletions

View File

@ -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);
}
}

View File

@ -4501,9 +4501,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
THashSet<RoomTile> 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<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
@ -4610,10 +4612,14 @@ public class Room implements Comparable<Room>, 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<Room>, ISerialize, Runnable {
//Check if can be placed at new position
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
THashSet<RoomTile> 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<Room>, 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<Room>, 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;
}

View File

@ -160,8 +160,9 @@ public class WiredHandler {
public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff, final THashSet<InteractionWiredEffect> 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<InteractionWiredCondition> conditions = room.getRoomSpecialTypes().getConditions(trigger.getX(), trigger.getY());
THashSet<InteractionWiredEffect> effects = room.getRoomSpecialTypes().getEffects(trigger.getX(), trigger.getY());
@ -193,7 +194,7 @@ public class WiredHandler {
THashSet<InteractionWiredExtra> extras = room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY());
for (InteractionWiredExtra extra : extras) {
extra.activateBox(room);
extra.activateBox(room, roomUnit, millis);
}
List<InteractionWiredEffect> 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);
}