Fix Interaction Water

This commit is contained in:
brenoepic 2022-04-16 03:19:30 -03:00 committed by Harmonic
parent 0fb8dad0ea
commit 9f9bbf1a37
2 changed files with 79 additions and 66 deletions

View File

@ -59,6 +59,7 @@ public class InteractionWater extends InteractionDefault {
} catch (Exception e) {
}
}
}
@Override
@ -72,26 +73,32 @@ public class InteractionWater extends InteractionDefault {
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
roomUnit.isSwimming = true;
Pet pet = room.getPet(roomUnit);
if(pet == null)
if (pet == null)
return;
if (!pet.getRoomUnit().hasStatus(RoomUnitStatus.SWIM) && pet.getPetData().canSwim) {
pet.getRoomUnit().setStatus(RoomUnitStatus.SWIM, "");
pet.packetUpdate = true;
}
}
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
roomUnit.isSwimming = false;
super.onWalkOff(roomUnit, room, objects);
Pet pet = room.getPet(roomUnit);
if ( roomUnit.getRoomUnitType() != RoomUnitType.PET) return;
Pet pet = room.getPet(roomUnit);
if(pet == null)
return;
if (pet == null) return;
pet.getRoomUnit().removeStatus(RoomUnitStatus.SWIM);
roomUnit.removeStatus(RoomUnitStatus.SWIM);
pet.packetUpdate = true;
}
@Override
@ -108,9 +115,8 @@ public class InteractionWater extends InteractionDefault {
public boolean canStackAt(Room room, List<Pair<RoomTile, THashSet<HabboItem>>> itemsAtLocation) {
for (Pair<RoomTile, THashSet<HabboItem>> set : itemsAtLocation) {
for (HabboItem item : set.getValue()) {
if (!(item instanceof InteractionWater)) {
return false;
}
if(item != this)
return false;
}
}

View File

@ -78,8 +78,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -584,7 +584,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (HabboItem item : items) {
if (exclude != null && item == exclude) continue;
if(item.getBaseItem().allowLay()) {
if (item.getBaseItem().allowLay()) {
return RoomTileState.LAY;
}
@ -593,7 +593,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
highestItem = item;*/
if(tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
continue;
result = this.checkStateForItem(item, tile);
@ -787,7 +787,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
habbo.getRoomUnit().setPreviousLocationZ(z);
}
if(habbo.getRoomUnit().getCurrentLocation().is(x, y) && (oldZ != z || updated || oldRotation != habbo.getRoomUnit().getBodyRotation())) {
if (habbo.getRoomUnit().getCurrentLocation().is(x, y) && (oldZ != z || updated || oldRotation != habbo.getRoomUnit().getBodyRotation())) {
habbo.getRoomUnit().statusUpdate(true);
//roomUnits.add(habbo.getRoomUnit());
}
@ -1454,7 +1454,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (RoomUnit unit : unitsOnTile) {
if (rolledUnitIds.contains(unit.getId())) continue;
if(usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
if (usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break;
if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable()))
continue;
@ -1502,7 +1502,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
Emulator.getThreading().run(() -> {
if (unit.getGoal() == rollerTile) {
try {
item.onWalkOn(unit, room, new Object[] { rollerTile, tileInFront });
item.onWalkOn(unit, room, new Object[]{rollerTile, tileInFront});
} catch (Exception e) {
LOGGER.error("Caught exception", e);
}
@ -2055,7 +2055,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (Pet pet : toRemovePets) {
removedPets.add(pet);
pet.removeFromRoom();
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId());
@ -2211,7 +2211,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public Game getGameOrCreate(Class<? extends Game> gameType) {
Game game = this.getGame(gameType);
if(game == null) {
if (game == null) {
try {
game = gameType.getDeclaredConstructor(Room.class).newInstance(this);
this.addGame(game);
@ -2968,8 +2968,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
list.add(bot.getRoomUnit());
}
for(Habbo habbo : this.getHabbosAt(tile))
{
for (Habbo habbo : this.getHabbosAt(tile)) {
list.add(habbo.getRoomUnit());
}
@ -3141,7 +3140,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (roomChatMessage == null || roomChatMessage.getMessage() == null || roomChatMessage.getMessage().equals(""))
return;
if(!habbo.hasPermission(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) {
if (!habbo.hasPermission(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) {
for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) {
if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentLocation())) {
return;
@ -3214,14 +3213,14 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
if(prefixMessage == null) {
if (prefixMessage == null) {
prefixMessage = roomChatMessage.getHabbo().getHabboInfo().getRank().hasPrefix() ? new RoomUserNameChangedComposer(habbo, true).compose() : null;
}
ServerMessage clearPrefixMessage = prefixMessage != null ? new RoomUserNameChangedComposer(habbo).compose() : null;
Rectangle tentRectangle = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation());
String trimmedMessage = roomChatMessage.getMessage().replaceAll("\\s+$","");
String trimmedMessage = roomChatMessage.getMessage().replaceAll("\\s+$", "");
if (trimmedMessage.isEmpty()) trimmedMessage = " ";
@ -3356,9 +3355,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
/**
* Sends the given message to the receiving Habbo if the Habbo has the ACC_SEE_TENTCHAT permission and is not within the tent
* @param receivingHabbo The receiving Habbo
*
* @param receivingHabbo The receiving Habbo
* @param roomChatMessage The message to receive
* @param tentRectangle The whole tent area from where the sending Habbo is saying something
* @param tentRectangle The whole tent area from where the sending Habbo is saying something
*/
private void showTentChatMessageOutsideTentIfPermitted(Habbo receivingHabbo, RoomChatMessage roomChatMessage, Rectangle tentRectangle) {
if (receivingHabbo != null && receivingHabbo.hasPermission(Permission.ACC_SEE_TENTCHAT) && tentRectangle != null && !RoomLayout.tileInSquare(tentRectangle, receivingHabbo.getRoomUnit().getCurrentLocation())) {
@ -3446,7 +3446,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.loaded) {
THashSet<HabboItem> cachedItems = this.tileCache.get(tile);
if(cachedItems != null)
if (cachedItems != null)
return cachedItems;
}
@ -3472,8 +3472,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item.getRotation() != 2 && item.getRotation() != 6) {
width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
}
else {
} else {
width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1;
length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1;
}
@ -3483,7 +3482,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
items.add(item);
if(returnOnFirst) {
if (returnOnFirst) {
return items;
}
}
@ -3522,7 +3521,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public boolean hasItemsAt(int x, int y) {
RoomTile tile = this.getLayout().getTile((short) x, (short) y);
if(tile == null)
if (tile == null)
return false;
return this.getItemsAt(tile, true).size() > 0;
@ -3535,13 +3534,13 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public HabboItem getTopItemAt(int x, int y, HabboItem exclude) {
RoomTile tile = this.getLayout().getTile((short) x, (short) y);
if(tile == null)
if (tile == null)
return null;
HabboItem highestItem = null;
for (HabboItem item : this.getItemsAt(x, y)) {
if(exclude != null && exclude == item)
if (exclude != null && exclude == item)
continue;
if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
@ -3555,7 +3554,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public HabboItem getTopItemAt(THashSet<RoomTile> tiles, HabboItem exclude) {
HabboItem highestItem = null;
for(RoomTile tile : tiles) {
for (RoomTile tile : tiles) {
if (tile == null)
continue;
@ -3603,10 +3602,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (items != null && !items.isEmpty()) {
for (HabboItem item : items) {
if(!item.getBaseItem().allowSit())
if (!item.getBaseItem().allowSit())
continue;
if(lowestChair != null && lowestChair.getZ() < item.getZ())
if (lowestChair != null && lowestChair.getZ() < item.getZ())
continue;
lowestChair = item;
@ -3623,10 +3622,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (items != null && !items.isEmpty()) {
for (HabboItem item : items) {
if(!item.getBaseItem().allowSit())
if (!item.getBaseItem().allowSit())
continue;
if(lowestChair != null && lowestChair.getZ() + Item.getCurrentHeight(lowestChair) > item.getZ() + Item.getCurrentHeight(item))
if (lowestChair != null && lowestChair.getZ() + Item.getCurrentHeight(lowestChair) > item.getZ() + Item.getCurrentHeight(item))
continue;
lowestChair = item;
@ -3640,10 +3639,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (x < 0 || y < 0 || this.layout == null)
return calculateHeightmap ? Short.MAX_VALUE : 0.0;
if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) {
FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this));
if(event.hasPluginHelper()) {
if (event.hasPluginHelper()) {
return calculateHeightmap ? event.getHeight() * 256.0D : event.getHeight();
}
}
@ -3653,8 +3652,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
THashSet<HabboItem> stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y);
if(stackHelpers.size() > 0) {
for(HabboItem item : stackHelpers) {
if (stackHelpers.size() > 0) {
for (HabboItem item : stackHelpers) {
if (item == exclude) continue;
return calculateHeightmap ? item.getZ() * 256.0D : item.getZ();
}
@ -3749,7 +3748,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
HabboItem tallestItem = null;
for (HabboItem item : items) {
if(tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
continue;
tallestItem = item;
@ -3964,7 +3963,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return;
this.sendComposer(new RoomRemoveRightsListComposer(this, userId).compose());
if (this.rights.remove(userId)) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ? AND user_id = ?")) {
statement.setInt(1, this.id);
@ -4124,11 +4123,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
public void giveEffect(RoomUnit roomUnit, int effectId, int duration) {
if(roomUnit == null) return;
if (roomUnit == null) return;
Habbo habbo = roomUnit.getRoom().getHabbo(roomUnit);
if(habbo == null) return;
if (habbo == null) return;
if (!habbo.getHabboInfo().isInGame()) {
if (duration == -1 || duration == Integer.MAX_VALUE) {
@ -4137,7 +4136,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
duration += Emulator.getIntUnixTimestamp();
}
if (this.allowEffects) {
if (this.allowEffects && !roomUnit.isSwimming) {
roomUnit.setEffectId(effectId, duration);
this.sendComposer(new RoomUserEffectComposer(roomUnit).compose());
}
@ -4180,8 +4179,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
if(item instanceof InteractionMultiHeight) {
((InteractionMultiHeight)item).updateUnitsOnItem(this);
if (item instanceof InteractionMultiHeight) {
((InteractionMultiHeight) item).updateUnitsOnItem(this);
}
}
}
@ -4348,7 +4347,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
public void dance(RoomUnit unit, DanceType danceType) {
if(unit.getDanceType() != danceType) {
if (unit.getDanceType() != danceType) {
boolean isDancing = !unit.getDanceType().equals(DanceType.NONE);
unit.setDanceType(danceType);
this.sendComposer(new RoomUserDanceComposer(unit).compose());
@ -4483,7 +4482,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (tile == null || tile.state == RoomTileState.INVALID) {
return FurnitureMovementError.INVALID_MOVE;
}
rotation %= 8;
if (this.hasRights(habbo) || this.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS) || habbo.hasPermission(Permission.ACC_MOVEROTATE)) {
return FurnitureMovementError.NONE;
@ -4503,7 +4502,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionBuildArea.class)) {
if (((InteractionBuildArea) area).inSquare(tile) && ((InteractionBuildArea) area).isBuilder(habbo.getHabboInfo().getUsername())) {
return FurnitureMovementError.NONE;
return FurnitureMovementError.NONE;
}
}
@ -4520,6 +4519,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (item instanceof InteractionStackHelper) return FurnitureMovementError.NONE;
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;
@ -4530,6 +4530,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
Optional<HabboItem> stackHelper = this.getItemsAt(tile).stream().filter(i -> i instanceof InteractionStackHelper).findAny();
List<Pair<RoomTile, THashSet<HabboItem>>> tileFurniList = new ArrayList<>();
for (RoomTile t : occupiedTiles) {
tileFurniList.add(Pair.create(t, this.getItemsAt(t)));
@ -4538,6 +4540,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (topItem != null && !topItem.getBaseItem().allowStack() && !t.getAllowStack()) {
return FurnitureMovementError.CANT_STACK;
}
if ((stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class) || topItem != null && (topItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (item.getBaseItem().getInteractionType().getType() == InteractionWater.class || item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class))) {
return FurnitureMovementError.CANT_STACK;
}
}
if (!item.canStackAt(this, tileFurniList)) {
@ -4569,9 +4575,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
double height = tile.getStackHeight();
for(RoomTile tile2 : occupiedTiles) {
for (RoomTile tile2 : occupiedTiles) {
double sHeight = tile2.getStackHeight();
if(sHeight > height) {
if (sHeight > height) {
height = sHeight;
}
}
@ -4647,7 +4653,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
boolean pluginHelper = false;
if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) {
FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile));
if(event.isCancelled()) {
if (event.isCancelled()) {
return FurnitureMovementError.CANCEL_PLUGIN_MOVE;
}
pluginHelper = event.hasPluginHelper();
@ -4663,14 +4669,14 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
HabboItem topItem = this.getTopItemAt(occupiedTiles, null);
if (!stackHelper.isPresent() && !pluginHelper) {
if ((!stackHelper.isPresent() && !pluginHelper) || item.getBaseItem().getInteractionType().getType() == InteractionWater.class) {
if (oldLocation != tile) {
for (RoomTile t : occupiedTiles) {
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))))
if ((!magicTile && ((tileTopItem != null && tileTopItem != item ? (t.state.equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack() || (tileTopItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && item.getBaseItem().getInteractionType().getType() == InteractionWater.class || item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class)) : this.calculateTileState(t, item).equals(RoomTileState.INVALID))) || stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class))
return FurnitureMovementError.CANT_STACK;
if(!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())) {
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;
@ -4706,8 +4712,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
if((!stackHelper.isPresent() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack())|| (topItem != null && topItem != item && topItem.getZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > MAXIMUM_FURNI_HEIGHT))
{
if ((!stackHelper.isPresent() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack()) || (topItem != null && topItem != item && topItem.getZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > MAXIMUM_FURNI_HEIGHT)) {
item.setRotation(oldRotation);
return FurnitureMovementError.CANT_STACK;
}
@ -4724,9 +4729,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
height = item.getZ();
} else {
height = this.getStackHeight(tile.x, tile.y, false, item);
for(RoomTile til : occupiedTiles) {
for (RoomTile til : occupiedTiles) {
double sHeight = this.getStackHeight(til.x, til.y, false, item);
if(sHeight > height) {
if (sHeight > height) {
height = sHeight;
}
}
@ -4742,6 +4747,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
if(height > MAXIMUM_FURNI_HEIGHT) return FurnitureMovementError.CANT_STACK;
if(height < this.getLayout().getHeightAtSquare(tile.x, tile.y)) return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor
item.setX(tile.x);
item.setY(tile.y);
item.setZ(height);
@ -4759,7 +4767,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
item.needsUpdate(true);
Emulator.getThreading().run(item);
if(sendUpdates) {
if (sendUpdates) {
this.sendComposer(new FloorItemUpdateComposer(item).compose());
}
@ -4780,13 +4788,12 @@ 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)) {
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) {
} catch (Exception e) {
}
}