2018-07-06 13:30:00 +00:00
package com.eu.habbo.habbohotel.rooms ;
import com.eu.habbo.Emulator ;
import com.eu.habbo.habbohotel.bots.Bot ;
import com.eu.habbo.habbohotel.bots.VisitorBot ;
import com.eu.habbo.habbohotel.commands.CommandHandler ;
import com.eu.habbo.habbohotel.games.Game ;
import com.eu.habbo.habbohotel.guilds.Guild ;
import com.eu.habbo.habbohotel.guilds.GuildMember ;
import com.eu.habbo.habbohotel.items.FurnitureType ;
import com.eu.habbo.habbohotel.items.ICycleable ;
import com.eu.habbo.habbohotel.items.Item ;
import com.eu.habbo.habbohotel.items.interactions.* ;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate ;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard ;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer ;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere ;
import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter ;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile ;
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField ;
import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole ;
2020-02-08 18:22:06 +02:00
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest ;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNest ;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink ;
import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood ;
2018-09-28 19:25:00 +00:00
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.habbohotel.messenger.MessengerBuddy ;
2018-09-12 16:45:00 +00:00
import com.eu.habbo.habbohotel.permissions.Permission ;
2018-09-28 19:25:00 +00:00
import com.eu.habbo.habbohotel.pets.Pet ;
import com.eu.habbo.habbohotel.pets.PetManager ;
2019-05-13 04:11:27 +01:00
import com.eu.habbo.habbohotel.pets.RideablePet ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.habbohotel.users.* ;
2020-02-01 13:22:35 +02:00
import com.eu.habbo.habbohotel.wired.WiredHandler ;
import com.eu.habbo.habbohotel.wired.WiredTriggerType ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.messages.ISerialize ;
import com.eu.habbo.messages.ServerMessage ;
import com.eu.habbo.messages.outgoing.MessageComposer ;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer ;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer ;
import com.eu.habbo.messages.outgoing.guilds.GuildInfoComposer ;
import com.eu.habbo.messages.outgoing.hotelview.HotelViewComposer ;
2018-09-28 19:25:00 +00:00
import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer ;
import com.eu.habbo.messages.outgoing.inventory.AddPetComposer ;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollAnswerComposer ;
import com.eu.habbo.messages.outgoing.polls.infobus.SimplePollStartComposer ;
import com.eu.habbo.messages.outgoing.rooms.* ;
import com.eu.habbo.messages.outgoing.rooms.items.* ;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer ;
import com.eu.habbo.messages.outgoing.rooms.users.* ;
import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer ;
import com.eu.habbo.plugin.Event ;
2018-12-22 10:39:00 +00:00
import com.eu.habbo.plugin.events.furniture.* ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.plugin.events.rooms.RoomLoadedEvent ;
import com.eu.habbo.plugin.events.rooms.RoomUnloadedEvent ;
import com.eu.habbo.plugin.events.rooms.RoomUnloadingEvent ;
2020-06-08 17:46:19 +02:00
import com.eu.habbo.plugin.events.users.* ;
2018-07-06 13:30:00 +00:00
import com.eu.habbo.threading.runnables.YouAreAPirate ;
import gnu.trove.TCollections ;
import gnu.trove.iterator.TIntObjectIterator ;
import gnu.trove.list.array.TIntArrayList ;
import gnu.trove.map.TIntIntMap ;
import gnu.trove.map.TIntObjectMap ;
import gnu.trove.map.hash.THashMap ;
import gnu.trove.map.hash.TIntIntHashMap ;
import gnu.trove.map.hash.TIntObjectHashMap ;
import gnu.trove.procedure.TIntObjectProcedure ;
import gnu.trove.procedure.TObjectProcedure ;
import gnu.trove.set.hash.THashSet ;
import io.netty.util.internal.ConcurrentSet ;
2018-12-22 10:39:00 +00:00
import org.apache.commons.math3.util.Pair ;
2020-05-04 22:24:09 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
2018-07-06 13:30:00 +00:00
import java.awt.* ;
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.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ScheduledFuture ;
import java.util.concurrent.TimeUnit ;
2020-06-07 15:54:08 +03:00
import java.util.regex.Pattern ;
2020-02-01 13:22:35 +02:00
import java.util.stream.Collectors ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
public class Room implements Comparable < Room > , ISerialize , Runnable {
2020-05-04 22:24:09 +02:00
private static final Logger LOGGER = LoggerFactory . getLogger ( Room . class ) ;
2020-04-23 22:17:04 +01:00
public static final Comparator SORT_SCORE = ( o1 , o2 ) - > {
2019-05-26 21:14:53 +03:00
2020-04-23 22:17:04 +01:00
if ( ! ( o1 instanceof Room & & o2 instanceof Room ) )
return 0 ;
2019-05-26 21:14:53 +03:00
2020-04-23 22:17:04 +01:00
return ( ( Room ) o2 ) . getScore ( ) - ( ( Room ) o1 ) . getScore ( ) ;
2019-05-26 21:14:53 +03:00
} ;
2020-04-23 22:17:04 +01:00
public static final Comparator SORT_ID = ( o1 , o2 ) - > {
2019-05-26 21:14:53 +03:00
2020-04-23 22:17:04 +01:00
if ( ! ( o1 instanceof Room & & o2 instanceof Room ) )
return 0 ;
2019-05-26 21:14:53 +03:00
2020-04-23 22:17:04 +01:00
return ( ( Room ) o2 ) . getId ( ) - ( ( Room ) o1 ) . getId ( ) ;
2019-05-26 21:14:53 +03:00
} ;
private static final TIntObjectHashMap < RoomMoodlightData > defaultMoodData = new TIntObjectHashMap < > ( ) ;
2018-07-06 13:30:00 +00:00
//Configuration. Loaded from database & updated accordingly.
public static boolean HABBO_CHAT_DELAY = false ;
public static int MAXIMUM_BOTS = 10 ;
public static int MAXIMUM_PETS = 10 ;
2019-12-23 15:12:13 +02:00
public static int MAXIMUM_FURNI = 2500 ;
2020-04-23 22:17:04 +01:00
public static int MAXIMUM_POSTITNOTES = 200 ;
2018-07-06 13:30:00 +00:00
public static int HAND_ITEM_TIME = 10 ;
public static int IDLE_CYCLES = 240 ;
public static int IDLE_CYCLES_KICK = 480 ;
public static String PREFIX_FORMAT = " [<font color= \" %color% \" >%prefix%</font>] " ;
2020-09-01 20:47:49 +02:00
public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1 ;
2020-10-13 03:42:30 +02:00
public static boolean MUTEAREA_CAN_WHISPER = false ;
2020-10-22 02:09:35 +02:00
public static double MAXIMUM_FURNI_HEIGHT = 40d ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
static {
for ( int i = 1 ; i < = 3 ; i + + ) {
2018-07-06 13:30:00 +00:00
RoomMoodlightData data = RoomMoodlightData . fromString ( " " ) ;
data . setId ( i ) ;
defaultMoodData . put ( i , data ) ;
}
}
2019-05-26 21:14:53 +03:00
public final Object roomUnitLock = new Object ( ) ;
public final ConcurrentHashMap < RoomTile , THashSet < HabboItem > > tileCache = new ConcurrentHashMap < > ( ) ;
public final List < Integer > userVotes ;
private final ConcurrentHashMap < Integer , Habbo > currentHabbos = new ConcurrentHashMap < > ( 3 ) ;
private final TIntObjectMap < Habbo > habboQueue = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
private final TIntObjectMap < Bot > currentBots = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
private final TIntObjectMap < Pet > currentPets = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
private final THashSet < RoomTrade > activeTrades ;
private final TIntArrayList rights ;
private final TIntIntHashMap mutedHabbos ;
private final TIntObjectHashMap < RoomBan > bannedHabbos ;
private final ConcurrentSet < Game > games ;
private final TIntObjectMap < String > furniOwnerNames ;
private final TIntIntMap furniOwnerCount ;
private final TIntObjectMap < RoomMoodlightData > moodlightData ;
private final THashSet < String > wordFilterWords ;
private final TIntObjectMap < HabboItem > roomItems ;
private final Object loadLock = new Object ( ) ;
//Use appropriately. Could potentially cause memory leaks when used incorrectly.
public volatile boolean preventUnloading = false ;
public volatile boolean preventUncaching = false ;
public ConcurrentSet < ServerMessage > scheduledComposers = new ConcurrentSet < > ( ) ;
public ConcurrentSet < Runnable > scheduledTasks = new ConcurrentSet < > ( ) ;
public String wordQuiz = " " ;
public int noVotes = 0 ;
public int yesVotes = 0 ;
public int wordQuizEnd = 0 ;
public ScheduledFuture roomCycleTask ;
2018-07-06 13:30:00 +00:00
private int id ;
private int ownerId ;
private String ownerName ;
private String name ;
private String description ;
private RoomLayout layout ;
private boolean overrideModel ;
private String layoutName ;
private String password ;
private RoomState state ;
private int usersMax ;
private volatile int score ;
private volatile int category ;
private String floorPaint ;
private String wallPaint ;
private String backgroundPaint ;
private int wallSize ;
private int wallHeight ;
private int floorSize ;
private int guild ;
private String tags ;
private volatile boolean publicRoom ;
private volatile boolean staffPromotedRoom ;
private volatile boolean allowPets ;
private volatile boolean allowPetsEat ;
private volatile boolean allowWalkthrough ;
private volatile boolean allowBotsWalk ;
private volatile boolean allowEffects ;
private volatile boolean hideWall ;
private volatile int chatMode ;
private volatile int chatWeight ;
private volatile int chatSpeed ;
private volatile int chatDistance ;
private volatile int chatProtection ;
private volatile int muteOption ;
private volatile int kickOption ;
private volatile int banOption ;
private volatile int pollId ;
private volatile boolean promoted ;
private volatile int tradeMode ;
private volatile boolean moveDiagonally ;
private volatile boolean jukeboxActive ;
2019-03-18 01:22:00 +00:00
private volatile boolean hideWired ;
2018-07-06 13:30:00 +00:00
private RoomPromotion promotion ;
private volatile boolean needsUpdate ;
private volatile boolean loaded ;
private volatile boolean preLoaded ;
2019-03-18 01:22:00 +00:00
private int idleCycles ;
2018-07-06 13:30:00 +00:00
private volatile int unitCounter ;
private volatile int rollerSpeed ;
2020-06-12 22:10:05 +02:00
private final int muteTime = Emulator . getConfig ( ) . getInt ( " hotel.flood.mute.time " , 30 ) ;
2019-03-18 01:22:00 +00:00
private long rollerCycle = System . currentTimeMillis ( ) ;
2018-07-06 13:30:00 +00:00
private volatile int lastTimerReset = Emulator . getIntUnixTimestamp ( ) ;
private volatile boolean muted ;
private RoomSpecialTypes roomSpecialTypes ;
private TraxManager traxManager ;
2020-06-12 22:10:05 +02:00
private boolean cycleOdd ;
2019-03-18 01:22:00 +00:00
private long cycleTimestamp ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
public Room ( ResultSet set ) throws SQLException {
2018-07-06 13:30:00 +00:00
this . id = set . getInt ( " id " ) ;
this . ownerId = set . getInt ( " owner_id " ) ;
this . ownerName = set . getString ( " owner_name " ) ;
this . name = set . getString ( " name " ) ;
this . description = set . getString ( " description " ) ;
this . password = set . getString ( " password " ) ;
this . state = RoomState . valueOf ( set . getString ( " state " ) . toUpperCase ( ) ) ;
this . usersMax = set . getInt ( " users_max " ) ;
this . score = set . getInt ( " score " ) ;
this . category = set . getInt ( " category " ) ;
this . floorPaint = set . getString ( " paper_floor " ) ;
this . wallPaint = set . getString ( " paper_wall " ) ;
this . backgroundPaint = set . getString ( " paper_landscape " ) ;
this . wallSize = set . getInt ( " thickness_wall " ) ;
this . wallHeight = set . getInt ( " wall_height " ) ;
this . floorSize = set . getInt ( " thickness_floor " ) ;
this . tags = set . getString ( " tags " ) ;
this . publicRoom = set . getBoolean ( " is_public " ) ;
this . staffPromotedRoom = set . getBoolean ( " is_staff_picked " ) ;
this . allowPets = set . getBoolean ( " allow_other_pets " ) ;
this . allowPetsEat = set . getBoolean ( " allow_other_pets_eat " ) ;
this . allowWalkthrough = set . getBoolean ( " allow_walkthrough " ) ;
this . hideWall = set . getBoolean ( " allow_hidewall " ) ;
this . chatMode = set . getInt ( " chat_mode " ) ;
this . chatWeight = set . getInt ( " chat_weight " ) ;
this . chatSpeed = set . getInt ( " chat_speed " ) ;
this . chatDistance = set . getInt ( " chat_hearing_distance " ) ;
this . chatProtection = set . getInt ( " chat_protection " ) ;
this . muteOption = set . getInt ( " who_can_mute " ) ;
this . kickOption = set . getInt ( " who_can_kick " ) ;
this . banOption = set . getInt ( " who_can_ban " ) ;
this . pollId = set . getInt ( " poll_id " ) ;
this . guild = set . getInt ( " guild_id " ) ;
this . rollerSpeed = set . getInt ( " roller_speed " ) ;
this . overrideModel = set . getString ( " override_model " ) . equals ( " 1 " ) ;
this . layoutName = set . getString ( " model " ) ;
this . promoted = set . getString ( " promoted " ) . equals ( " 1 " ) ;
this . jukeboxActive = set . getString ( " jukebox_active " ) . equals ( " 1 " ) ;
2018-10-06 22:28:00 +00:00
this . hideWired = set . getString ( " hidewired " ) . equals ( " 1 " ) ;
2018-07-06 13:30:00 +00:00
2018-09-28 19:25:00 +00:00
this . bannedHabbos = new TIntObjectHashMap < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1 " ) ) {
if ( this . promoted ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , Emulator . getIntUnixTimestamp ( ) ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet promotionSet = statement . executeQuery ( ) ) {
2018-07-06 13:30:00 +00:00
this . promoted = false ;
2019-05-26 21:14:53 +03:00
if ( promotionSet . next ( ) ) {
2018-07-06 13:30:00 +00:00
this . promoted = true ;
this . promotion = new RoomPromotion ( this , promotionSet ) ;
}
}
}
this . loadBans ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-05-23 23:57:22 +01:00
}
2018-07-06 13:30:00 +00:00
this . tradeMode = set . getInt ( " trade_mode " ) ;
this . moveDiagonally = set . getString ( " move_diagonally " ) . equals ( " 1 " ) ;
this . preLoaded = true ;
this . allowBotsWalk = true ;
this . allowEffects = true ;
2018-09-28 19:25:00 +00:00
this . furniOwnerNames = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
2018-07-06 13:30:00 +00:00
this . furniOwnerCount = TCollections . synchronizedMap ( new TIntIntHashMap ( 0 ) ) ;
2018-09-28 19:25:00 +00:00
this . roomItems = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
this . wordFilterWords = new THashSet < > ( 0 ) ;
this . moodlightData = new TIntObjectHashMap < > ( defaultMoodData ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( String s : set . getString ( " moodlight_data " ) . split ( " ; " ) ) {
2018-07-06 13:30:00 +00:00
RoomMoodlightData data = RoomMoodlightData . fromString ( s ) ;
this . moodlightData . put ( data . getId ( ) , data ) ;
}
this . mutedHabbos = new TIntIntHashMap ( ) ;
2018-09-28 19:25:00 +00:00
this . games = new ConcurrentSet < > ( ) ;
2018-07-06 13:30:00 +00:00
2018-09-28 19:25:00 +00:00
this . activeTrades = new THashSet < > ( 0 ) ;
2018-07-06 13:30:00 +00:00
this . rights = new TIntArrayList ( ) ;
this . userVotes = new ArrayList < > ( ) ;
}
2019-05-26 21:14:53 +03:00
public synchronized void loadData ( ) {
synchronized ( this . loadLock ) {
2018-07-06 13:30:00 +00:00
if ( ! this . preLoaded | | this . loaded )
return ;
this . preLoaded = false ;
2019-05-26 21:14:53 +03:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ) {
synchronized ( this . roomUnitLock ) {
2018-07-06 13:30:00 +00:00
this . unitCounter = 0 ;
this . currentHabbos . clear ( ) ;
this . currentPets . clear ( ) ;
this . currentBots . clear ( ) ;
}
this . roomSpecialTypes = new RoomSpecialTypes ( ) ;
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadLayout ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadRights ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadItems ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadHeightmap ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadBots ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadPets ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadWordFilter ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
this . loadWiredData ( connection ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
this . idleCycles = 0 ;
this . loaded = true ;
this . roomCycleTask = Emulator . getThreading ( ) . getService ( ) . scheduleAtFixedRate ( this , 500 , 500 , TimeUnit . MILLISECONDS ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
this . traxManager = new TraxManager ( this ) ;
2019-05-26 21:14:53 +03:00
if ( this . jukeboxActive ) {
2018-07-06 13:30:00 +00:00
this . traxManager . play ( 0 ) ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . roomSpecialTypes . getItemsOfType ( InteractionJukeBox . class ) ) {
2018-07-06 13:30:00 +00:00
item . setExtradata ( " 1 " ) ;
this . updateItem ( item ) ;
}
}
}
Emulator . getPluginManager ( ) . fireEvent ( new RoomLoadedEvent ( this ) ) ;
}
2019-05-26 21:14:53 +03:00
private synchronized void loadLayout ( ) {
if ( this . layout = = null ) {
if ( this . overrideModel ) {
2018-07-06 13:30:00 +00:00
this . layout = Emulator . getGameEnvironment ( ) . getRoomManager ( ) . loadCustomLayout ( this ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
this . layout = Emulator . getGameEnvironment ( ) . getRoomManager ( ) . loadLayout ( this . layoutName , this ) ;
}
}
}
2019-05-26 21:14:53 +03:00
private synchronized void loadHeightmap ( ) {
if ( this . layout ! = null ) {
for ( short x = 0 ; x < this . layout . getMapSizeX ( ) ; x + + ) {
for ( short y = 0 ; y < this . layout . getMapSizeY ( ) ; y + + ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( x , y ) ;
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
this . updateTile ( tile ) ;
}
}
}
2019-05-26 21:14:53 +03:00
} else {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Unknown Room Layout for Room (ID: {}) " , this . id ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private synchronized void loadItems ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . roomItems . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM items WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
this . addHabboItem ( Emulator . getGameEnvironment ( ) . getItemManager ( ) . loadHabboItem ( set ) ) ;
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-05-23 23:57:22 +01:00
}
2019-12-23 15:12:13 +02:00
if ( this . itemCount ( ) > Room . MAXIMUM_FURNI ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Room ID: {} has exceeded the furniture limit ({} > {}). " , this . getId ( ) , this . itemCount ( ) , Room . MAXIMUM_FURNI ) ;
2019-12-23 15:12:13 +02:00
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
private synchronized void loadWiredData ( Connection connection ) {
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>'' " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
try {
2018-07-06 13:30:00 +00:00
HabboItem item = this . getHabboItem ( set . getInt ( " id " ) ) ;
2019-05-26 21:14:53 +03:00
if ( item instanceof InteractionWired ) {
2018-07-06 13:30:00 +00:00
( ( InteractionWired ) item ) . loadWiredData ( set , this ) ;
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private synchronized void loadBots ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . currentBots . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
Bot b = Emulator . getGameEnvironment ( ) . getBotManager ( ) . loadBot ( set ) ;
2019-05-26 21:14:53 +03:00
if ( b ! = null ) {
2018-07-06 13:30:00 +00:00
b . setRoom ( this ) ;
b . setRoomUnit ( new RoomUnit ( ) ) ;
b . getRoomUnit ( ) . setPathFinderRoom ( this ) ;
b . getRoomUnit ( ) . setLocation ( this . layout . getTile ( ( short ) set . getInt ( " x " ) , ( short ) set . getInt ( " y " ) ) ) ;
2019-05-26 21:14:53 +03:00
if ( b . getRoomUnit ( ) . getCurrentLocation ( ) = = null ) {
2018-07-06 13:30:00 +00:00
b . getRoomUnit ( ) . setLocation ( this . getLayout ( ) . getDoorTile ( ) ) ;
b . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( this . getLayout ( ) . getDoorDirection ( ) ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
b . getRoomUnit ( ) . setZ ( set . getDouble ( " z " ) ) ;
2020-01-27 21:56:59 +02:00
b . getRoomUnit ( ) . setPreviousLocationZ ( set . getDouble ( " z " ) ) ;
2018-07-06 13:30:00 +00:00
b . getRoomUnit ( ) . setRotation ( RoomUserRotation . values ( ) [ set . getInt ( " rot " ) ] ) ;
}
b . getRoomUnit ( ) . setRoomUnitType ( RoomUnitType . BOT ) ;
b . getRoomUnit ( ) . setDanceType ( DanceType . values ( ) [ set . getInt ( " dance " ) ] ) ;
2018-10-06 22:28:00 +00:00
//b.getRoomUnit().setCanWalk(set.getBoolean("freeroam"));
2018-07-06 13:30:00 +00:00
b . getRoomUnit ( ) . setInRoom ( true ) ;
2019-04-21 23:42:00 +00:00
this . giveEffect ( b . getRoomUnit ( ) , set . getInt ( " effect " ) , Integer . MAX_VALUE ) ;
2018-07-06 13:30:00 +00:00
this . addBot ( b ) ;
}
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private synchronized void loadPets ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . currentPets . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
try {
2018-09-12 16:45:00 +00:00
Pet pet = PetManager . loadPet ( set ) ;
2018-07-06 13:30:00 +00:00
pet . setRoom ( this ) ;
pet . setRoomUnit ( new RoomUnit ( ) ) ;
pet . getRoomUnit ( ) . setPathFinderRoom ( this ) ;
pet . getRoomUnit ( ) . setLocation ( this . layout . getTile ( ( short ) set . getInt ( " x " ) , ( short ) set . getInt ( " y " ) ) ) ;
2019-05-26 21:14:53 +03:00
if ( pet . getRoomUnit ( ) . getCurrentLocation ( ) = = null ) {
2018-07-06 13:30:00 +00:00
pet . getRoomUnit ( ) . setLocation ( this . getLayout ( ) . getDoorTile ( ) ) ;
pet . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( this . getLayout ( ) . getDoorDirection ( ) ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
pet . getRoomUnit ( ) . setZ ( set . getDouble ( " z " ) ) ;
pet . getRoomUnit ( ) . setRotation ( RoomUserRotation . values ( ) [ set . getInt ( " rot " ) ] ) ;
}
pet . getRoomUnit ( ) . setRoomUnitType ( RoomUnitType . PET ) ;
pet . getRoomUnit ( ) . setCanWalk ( true ) ;
this . addPet ( pet ) ;
this . getFurniOwnerNames ( ) . put ( pet . getUserId ( ) , set . getString ( " pet_owner_name " ) ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-05-23 23:57:22 +01:00
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
private synchronized void loadWordFilter ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . wordFilterWords . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM room_wordfilter WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
this . wordFilterWords . add ( set . getString ( " word " ) ) ;
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-05-23 23:57:22 +01:00
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void updateTile ( RoomTile tile ) {
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
tile . setStackHeight ( this . getStackHeight ( tile . x , tile . y , false ) ) ;
2018-11-17 13:28:00 +00:00
tile . setState ( this . calculateTileState ( tile ) ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void updateTiles ( THashSet < RoomTile > tiles ) {
for ( RoomTile tile : tiles ) {
2018-07-06 13:30:00 +00:00
this . tileCache . remove ( tile ) ;
tile . setStackHeight ( this . getStackHeight ( tile . x , tile . y , false ) ) ;
2018-11-17 13:28:00 +00:00
tile . setState ( this . calculateTileState ( tile ) ) ;
2018-07-06 13:30:00 +00:00
}
2020-01-21 06:26:44 -05:00
this . sendComposer ( new UpdateStackHeightComposer ( this , tiles ) . compose ( ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
private RoomTileState calculateTileState ( RoomTile tile ) {
2019-03-18 01:22:00 +00:00
return this . calculateTileState ( tile , null ) ;
}
2019-05-26 21:14:53 +03:00
private RoomTileState calculateTileState ( RoomTile tile , HabboItem exclude ) {
2019-05-18 14:14:21 +01:00
if ( tile = = null | | tile . state = = RoomTileState . INVALID )
2018-11-17 13:28:00 +00:00
return RoomTileState . INVALID ;
RoomTileState result = RoomTileState . OPEN ;
2020-10-15 08:35:59 +02:00
//HabboItem highestItem = null;
//HabboItem lowestChair = this.getLowestChair(tile);
2019-06-16 17:31:50 +03:00
THashSet < HabboItem > items = this . getItemsAt ( tile ) ;
2020-02-27 22:35:03 +02:00
2020-08-16 03:01:37 +02:00
if ( items = = null ) return RoomTileState . INVALID ;
2020-02-27 22:35:03 +02:00
2020-10-15 08:35:59 +02:00
HabboItem tallestItem = null ;
2019-06-16 17:31:50 +03:00
for ( HabboItem item : items ) {
2019-03-18 01:22:00 +00:00
if ( exclude ! = null & & item = = exclude ) continue ;
2020-08-16 03:01:37 +02:00
if ( item . getBaseItem ( ) . allowLay ( ) ) {
return RoomTileState . LAY ;
}
2020-10-15 08:35:59 +02:00
/ * if ( highestItem ! = null & & highestItem . getZ ( ) + Item . getCurrentHeight ( highestItem ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
2020-08-16 03:01:37 +02:00
continue ;
2020-10-15 08:35:59 +02:00
highestItem = item ; * /
if ( tallestItem ! = null & & tallestItem . getZ ( ) + Item . getCurrentHeight ( tallestItem ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
continue ;
result = this . checkStateForItem ( item , tile ) ;
tallestItem = item ;
2020-08-16 03:01:37 +02:00
/ * if ( lowestChair ! = null & & item . getZ ( ) > lowestChair . getZ ( ) + 1 . 5 ) {
2018-11-17 13:28:00 +00:00
continue ;
}
2019-05-26 21:14:53 +03:00
if ( lowestItem = = null | | lowestItem . getZ ( ) < item . getZ ( ) ) {
2018-11-17 13:28:00 +00:00
lowestItem = item ;
2020-02-08 18:22:06 +02:00
result = this . checkStateForItem ( lowestItem , tile ) ;
2019-05-26 21:14:53 +03:00
} else if ( lowestItem . getZ ( ) = = item . getZ ( ) ) {
if ( result = = RoomTileState . OPEN ) {
2020-02-08 18:22:06 +02:00
result = this . checkStateForItem ( item , tile ) ;
2018-11-17 13:28:00 +00:00
}
2020-08-16 03:01:37 +02:00
} * /
2018-11-17 13:28:00 +00:00
}
2020-10-15 08:35:59 +02:00
//if (lowestChair != null) return RoomTileState.SIT;
2018-12-22 10:39:00 +00:00
2018-11-17 13:28:00 +00:00
return result ;
}
2020-02-08 18:22:06 +02:00
private RoomTileState checkStateForItem ( HabboItem item , RoomTile tile ) {
2018-11-17 13:28:00 +00:00
RoomTileState result = RoomTileState . BLOCKED ;
2019-05-26 21:14:53 +03:00
if ( item . isWalkable ( ) ) {
2018-11-17 13:28:00 +00:00
result = RoomTileState . OPEN ;
}
2019-05-26 21:14:53 +03:00
if ( item . getBaseItem ( ) . allowSit ( ) ) {
2018-11-17 13:28:00 +00:00
result = RoomTileState . SIT ;
}
2019-05-26 21:14:53 +03:00
if ( item . getBaseItem ( ) . allowLay ( ) ) {
2018-11-17 13:28:00 +00:00
result = RoomTileState . LAY ;
}
2020-02-08 18:22:06 +02:00
RoomTileState overriddenState = item . getOverrideTileState ( tile , this ) ;
if ( overriddenState ! = null ) {
result = overriddenState ;
}
2018-11-17 13:28:00 +00:00
return result ;
}
2019-05-26 21:14:53 +03:00
public boolean tileWalkable ( RoomTile t ) {
2018-07-06 13:30:00 +00:00
return this . tileWalkable ( t . x , t . y ) ;
}
2019-05-26 21:14:53 +03:00
public boolean tileWalkable ( short x , short y ) {
2018-07-06 13:30:00 +00:00
boolean walkable = this . layout . tileWalkable ( x , y ) ;
2019-05-12 08:59:01 +01:00
RoomTile tile = this . getLayout ( ) . getTile ( x , y ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( walkable & & tile ! = null ) {
if ( tile . hasUnits ( ) & & ! this . allowWalkthrough ) {
2018-07-06 13:30:00 +00:00
walkable = false ;
}
}
2018-09-28 19:25:00 +00:00
2019-05-12 08:59:01 +01:00
return walkable ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void pickUpItem ( HabboItem item , Habbo picker ) {
if ( item = = null )
2018-07-06 13:30:00 +00:00
return ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePickedUpEvent . class , true ) ) {
2018-07-06 13:30:00 +00:00
Event furniturePickedUpEvent = new FurniturePickedUpEvent ( item , picker ) ;
Emulator . getPluginManager ( ) . fireEvent ( furniturePickedUpEvent ) ;
2019-05-26 21:14:53 +03:00
if ( furniturePickedUpEvent . isCancelled ( ) )
2018-07-06 13:30:00 +00:00
return ;
}
this . removeHabboItem ( item . getId ( ) ) ;
item . onPickUp ( this ) ;
item . setRoomId ( 0 ) ;
item . needsUpdate ( true ) ;
2019-05-26 21:14:53 +03:00
if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
2018-09-28 19:25:00 +00:00
THashSet < RoomTile > updatedTiles = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
Rectangle rectangle = RoomLayout . getRectangle ( item . getX ( ) , item . getY ( ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
2019-05-26 21:14:53 +03:00
for ( short x = ( short ) rectangle . x ; x < rectangle . x + rectangle . getWidth ( ) ; x + + ) {
for ( short y = ( short ) rectangle . y ; y < rectangle . y + rectangle . getHeight ( ) ; y + + ) {
2018-07-06 13:30:00 +00:00
double stackHeight = this . getStackHeight ( x , y , false ) ;
RoomTile tile = this . layout . getTile ( x , y ) ;
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
tile . setStackHeight ( stackHeight ) ;
updatedTiles . add ( tile ) ;
}
}
}
2020-01-21 06:26:44 -05:00
this . sendComposer ( new UpdateStackHeightComposer ( this , updatedTiles ) . compose ( ) ) ;
2018-07-06 13:30:00 +00:00
this . updateTiles ( updatedTiles ) ;
2019-05-26 21:14:53 +03:00
for ( RoomTile tile : updatedTiles ) {
2018-07-06 13:30:00 +00:00
this . updateHabbosAt ( tile . x , tile . y ) ;
2019-05-12 10:41:57 -04:00
this . updateBotsAt ( tile . x , tile . y ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
} else if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . WALL ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RemoveWallItemComposer ( item ) . compose ( ) ) ;
}
Habbo habbo = ( picker ! = null & & picker . getHabboInfo ( ) . getId ( ) = = item . getId ( ) ? picker : Emulator . getGameServer ( ) . getGameClientManager ( ) . getHabbo ( item . getUserId ( ) ) ) ;
if ( habbo ! = null ) {
habbo . getInventory ( ) . getItemsComponent ( ) . addItem ( item ) ;
2018-11-17 13:28:00 +00:00
habbo . getClient ( ) . sendResponse ( new AddHabboItemComposer ( item ) ) ;
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new InventoryRefreshComposer ( ) ) ;
}
Emulator . getThreading ( ) . run ( item ) ;
}
2019-05-26 21:14:53 +03:00
public void updateHabbosAt ( Rectangle rectangle ) {
for ( short i = ( short ) rectangle . x ; i < rectangle . x + rectangle . width ; i + + ) {
for ( short j = ( short ) rectangle . y ; j < rectangle . y + rectangle . height ; j + + ) {
2018-07-06 13:30:00 +00:00
this . updateHabbosAt ( i , j ) ;
}
}
}
2019-05-26 21:14:53 +03:00
public void updateHabbo ( Habbo habbo ) {
2019-03-18 01:22:00 +00:00
this . updateRoomUnit ( habbo . getRoomUnit ( ) ) ;
2018-12-22 10:39:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void updateRoomUnit ( RoomUnit roomUnit ) {
2018-12-22 10:39:00 +00:00
HabboItem item = this . getTopItemAt ( roomUnit . getX ( ) , roomUnit . getY ( ) ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ( item = = null & & ! roomUnit . cmdSit ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowSit ( ) ) )
2018-12-22 10:39:00 +00:00
roomUnit . removeStatus ( RoomUnitStatus . SIT ) ;
2018-07-06 13:30:00 +00:00
2019-04-21 23:42:00 +00:00
double oldZ = roomUnit . getZ ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( item ! = null ) {
if ( item . getBaseItem ( ) . allowSit ( ) ) {
2018-12-22 10:39:00 +00:00
roomUnit . setZ ( item . getZ ( ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2019-05-12 08:59:01 +01:00
roomUnit . setZ ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( oldZ ! = roomUnit . getZ ( ) ) {
2020-04-23 18:08:37 +01:00
this . scheduledTasks . add ( ( ) - > {
try {
item . onWalkOn ( roomUnit , Room . this , null ) ;
} catch ( Exception e ) {
2019-04-21 23:42:00 +00:00
}
} ) ;
}
2018-07-06 13:30:00 +00:00
}
2018-12-22 10:39:00 +00:00
this . sendComposer ( new RoomUserStatusComposer ( roomUnit ) . compose ( ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void updateHabbosAt ( short x , short y ) {
2020-02-01 13:22:35 +02:00
this . updateHabbosAt ( x , y , this . getHabbosAt ( x , y ) ) ;
}
2018-07-06 13:30:00 +00:00
2020-02-01 13:22:35 +02:00
public void updateHabbosAt ( short x , short y , THashSet < Habbo > habbos ) {
2018-07-06 13:30:00 +00:00
HabboItem item = this . getTopItemAt ( x , y ) ;
2018-09-28 19:25:00 +00:00
THashSet < RoomUnit > roomUnits = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : habbos ) {
2020-05-03 00:33:02 +02:00
2020-10-15 08:35:59 +02:00
double oldZ = habbo . getRoomUnit ( ) . getZ ( ) ;
RoomUserRotation oldRotation = habbo . getRoomUnit ( ) . getBodyRotation ( ) ;
2020-05-03 00:33:02 +02:00
double z = habbo . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ;
2020-10-15 08:35:59 +02:00
boolean updated = false ;
2020-05-03 00:33:02 +02:00
2020-10-15 08:35:59 +02:00
if ( habbo . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . SIT ) & & ( ( item = = null & & ! habbo . getRoomUnit ( ) . cmdSit ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowSit ( ) ) ) ) {
2018-09-12 16:45:00 +00:00
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . SIT ) ;
2020-10-15 08:35:59 +02:00
updated = true ;
}
2018-07-06 13:30:00 +00:00
2020-10-15 08:35:59 +02:00
if ( habbo . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . LAY ) & & ( ( item = = null & & ! habbo . getRoomUnit ( ) . cmdLay ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowLay ( ) ) ) ) {
2018-09-12 16:45:00 +00:00
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . LAY ) ;
2020-10-15 08:35:59 +02:00
updated = true ;
}
2018-07-06 13:30:00 +00:00
2020-05-03 00:33:02 +02:00
if ( item ! = null & & ( item . getBaseItem ( ) . allowSit ( ) | | item . getBaseItem ( ) . allowLay ( ) ) ) {
habbo . getRoomUnit ( ) . setZ ( item . getZ ( ) ) ;
habbo . getRoomUnit ( ) . setPreviousLocationZ ( item . getZ ( ) ) ;
habbo . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( item . getRotation ( ) ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2020-05-03 00:33:02 +02:00
habbo . getRoomUnit ( ) . setZ ( z ) ;
habbo . getRoomUnit ( ) . setPreviousLocationZ ( z ) ;
2018-07-06 13:30:00 +00:00
}
2020-10-15 08:35:59 +02:00
if ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) . is ( x , y ) & & ( oldZ ! = z | | updated | | oldRotation ! = habbo . getRoomUnit ( ) . getBodyRotation ( ) ) ) {
2020-10-15 09:09:48 +02:00
habbo . getRoomUnit ( ) . statusUpdate ( true ) ;
//roomUnits.add(habbo.getRoomUnit());
2020-10-15 08:35:59 +02:00
}
2018-07-06 13:30:00 +00:00
}
2020-10-15 09:09:48 +02:00
/ * if ( ! roomUnits . isEmpty ( ) ) {
2019-03-18 01:22:00 +00:00
this . sendComposer ( new RoomUserStatusComposer ( roomUnits , true ) . compose ( ) ) ;
2020-10-15 09:09:48 +02:00
} * /
2018-07-06 13:30:00 +00:00
}
2020-01-22 10:22:05 -05:00
public void updateBotsAt ( short x , short y ) {
2019-05-12 10:41:57 -04:00
HabboItem topItem = this . getTopItemAt ( x , y ) ;
THashSet < RoomUnit > roomUnits = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( Bot bot : this . getBotsAt ( this . layout . getTile ( x , y ) ) ) {
if ( topItem ! = null ) {
if ( topItem . getBaseItem ( ) . allowSit ( ) ) {
2019-05-12 10:41:57 -04:00
bot . getRoomUnit ( ) . setZ ( topItem . getZ ( ) ) ;
bot . getRoomUnit ( ) . setPreviousLocationZ ( topItem . getZ ( ) ) ;
bot . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( topItem . getRotation ( ) ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2020-01-27 23:02:53 +02:00
bot . getRoomUnit ( ) . setZ ( topItem . getZ ( ) + Item . getCurrentHeight ( topItem ) ) ;
2019-05-12 10:41:57 -04:00
2019-05-26 21:14:53 +03:00
if ( topItem . getBaseItem ( ) . allowLay ( ) ) {
2019-05-12 10:41:57 -04:00
bot . getRoomUnit ( ) . setStatus ( RoomUnitStatus . LAY , ( topItem . getZ ( ) + topItem . getBaseItem ( ) . getHeight ( ) ) + " " ) ;
}
}
} else {
bot . getRoomUnit ( ) . setZ ( bot . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ) ;
2020-01-27 23:02:53 +02:00
bot . getRoomUnit ( ) . setPreviousLocationZ ( bot . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ) ;
2019-05-12 10:41:57 -04:00
}
roomUnits . add ( bot . getRoomUnit ( ) ) ;
}
2019-05-26 21:14:53 +03:00
if ( ! roomUnits . isEmpty ( ) ) {
2019-05-12 10:41:57 -04:00
this . sendComposer ( new RoomUserStatusComposer ( roomUnits , true ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public void pickupPetsForHabbo ( Habbo habbo ) {
2018-09-28 19:25:00 +00:00
THashSet < Pet > pets = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
synchronized ( this . currentPets ) {
for ( Pet pet : this . currentPets . valueCollection ( ) ) {
if ( pet . getUserId ( ) = = habbo . getHabboInfo ( ) . getId ( ) ) {
2018-09-28 19:25:00 +00:00
pets . add ( pet ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
for ( Pet pet : pets ) {
2019-05-12 08:59:01 +01:00
pet . removeFromRoom ( ) ;
Emulator . getThreading ( ) . run ( pet ) ;
2019-03-18 01:22:00 +00:00
habbo . getInventory ( ) . getPetsComponent ( ) . addPet ( pet ) ;
habbo . getClient ( ) . sendResponse ( new AddPetComposer ( pet ) ) ;
2018-07-06 13:30:00 +00:00
this . currentPets . remove ( pet . getId ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public void startTrade ( Habbo userOne , Habbo userTwo ) {
2018-07-06 13:30:00 +00:00
RoomTrade trade = new RoomTrade ( userOne , userTwo , this ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . activeTrades ) {
2018-07-06 13:30:00 +00:00
this . activeTrades . add ( trade ) ;
}
2018-10-06 22:28:00 +00:00
trade . start ( ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void stopTrade ( RoomTrade trade ) {
synchronized ( this . activeTrades ) {
2018-07-06 13:30:00 +00:00
this . activeTrades . remove ( trade ) ;
}
}
2019-05-26 21:14:53 +03:00
public RoomTrade getActiveTradeForHabbo ( Habbo user ) {
synchronized ( this . activeTrades ) {
for ( RoomTrade trade : this . activeTrades ) {
for ( RoomTradeUser habbo : trade . getRoomTradeUsers ( ) ) {
2018-07-06 13:30:00 +00:00
if ( habbo . getHabbo ( ) = = user )
return trade ;
}
}
}
return null ;
}
2019-05-26 21:14:53 +03:00
public synchronized void dispose ( ) {
synchronized ( this . loadLock ) {
2018-07-06 13:30:00 +00:00
if ( this . preventUnloading )
return ;
if ( Emulator . getPluginManager ( ) . fireEvent ( new RoomUnloadingEvent ( this ) ) . isCancelled ( ) )
return ;
2019-05-26 21:14:53 +03:00
if ( this . loaded ) {
try {
2020-03-26 19:29:13 +00:00
if ( this . traxManager ! = null & & ! this . traxManager . disposed ( ) ) {
2020-02-27 22:35:03 +02:00
this . traxManager . dispose ( ) ;
}
2018-07-06 13:30:00 +00:00
this . roomCycleTask . cancel ( false ) ;
this . scheduledTasks . clear ( ) ;
this . scheduledComposers . clear ( ) ;
this . loaded = false ;
this . tileCache . clear ( ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . mutedHabbos ) {
2018-07-06 13:30:00 +00:00
this . mutedHabbos . clear ( ) ;
}
2019-05-26 21:14:53 +03:00
for ( InteractionGameTimer timer : this . getRoomSpecialTypes ( ) . getGameTimers ( ) . values ( ) ) {
2019-05-04 21:41:18 +01:00
timer . setRunning ( false ) ;
}
2019-05-26 21:14:53 +03:00
for ( Game game : this . games ) {
2019-07-30 17:51:27 +03:00
game . dispose ( ) ;
2018-07-06 13:30:00 +00:00
}
this . games . clear ( ) ;
2019-05-06 05:23:51 +01:00
removeAllPets ( ownerId ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
if ( iterator . value ( ) . needsUpdate ( ) )
iterator . value ( ) . run ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2018-07-06 13:30:00 +00:00
break ;
}
}
}
2019-05-26 21:14:53 +03:00
if ( this . roomSpecialTypes ! = null ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . dispose ( ) ;
}
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
2018-07-06 13:30:00 +00:00
this . roomItems . clear ( ) ;
}
2019-05-26 21:14:53 +03:00
synchronized ( this . habboQueue ) {
2018-07-06 13:30:00 +00:00
this . habboQueue . clear ( ) ;
}
2018-09-28 19:25:00 +00:00
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : this . currentHabbos . values ( ) ) {
2018-07-06 13:30:00 +00:00
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
this . sendComposer ( new HotelViewComposer ( ) . compose ( ) ) ;
this . currentHabbos . clear ( ) ;
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
botIterator . advance ( ) ;
botIterator . value ( ) . needsUpdate ( true ) ;
Emulator . getThreading ( ) . run ( botIterator . value ( ) ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
break ;
}
}
this . currentBots . clear ( ) ;
this . currentPets . clear ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2020-02-27 22:35:03 +02:00
try {
this . wordQuiz = " " ;
this . yesVotes = 0 ;
this . noVotes = 0 ;
this . updateDatabaseUserCount ( ) ;
this . preLoaded = true ;
this . layout = null ;
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2020-02-27 22:35:03 +02:00
}
2018-07-06 13:30:00 +00:00
}
Emulator . getPluginManager ( ) . fireEvent ( new RoomUnloadedEvent ( this ) ) ;
}
@Override
2019-05-26 21:14:53 +03:00
public int compareTo ( Room o ) {
if ( o . getUserCount ( ) ! = this . getUserCount ( ) ) {
return o . getCurrentHabbos ( ) . size ( ) - this . getCurrentHabbos ( ) . size ( ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
return this . id - o . id ;
2018-07-06 13:30:00 +00:00
}
@Override
2019-05-26 21:14:53 +03:00
public void serialize ( ServerMessage message ) {
2018-07-06 13:30:00 +00:00
message . appendInt ( this . id ) ;
message . appendString ( this . name ) ;
2019-05-26 21:14:53 +03:00
if ( this . isPublicRoom ( ) ) {
2018-07-06 13:30:00 +00:00
message . appendInt ( 0 ) ;
message . appendString ( " " ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
message . appendInt ( this . ownerId ) ;
message . appendString ( this . ownerName ) ;
}
message . appendInt ( this . state . getState ( ) ) ;
message . appendInt ( this . getUserCount ( ) ) ;
message . appendInt ( this . usersMax ) ;
message . appendString ( this . description ) ;
message . appendInt ( 0 ) ;
message . appendInt ( this . score ) ;
message . appendInt ( 0 ) ;
message . appendInt ( this . category ) ;
2019-05-28 19:53:39 +03:00
String [ ] tags = Arrays . stream ( this . tags . split ( " ; " ) ) . filter ( t - > ! t . isEmpty ( ) ) . toArray ( String [ ] : : new ) ;
message . appendInt ( tags . length ) ;
for ( String s : tags ) {
2018-07-06 13:30:00 +00:00
message . appendString ( s ) ;
}
int base = 0 ;
2019-05-26 21:14:53 +03:00
if ( this . getGuildId ( ) > 0 ) {
2018-07-06 13:30:00 +00:00
base = base | 2 ;
}
2019-05-26 21:14:53 +03:00
if ( this . isPromoted ( ) ) {
2018-07-06 13:30:00 +00:00
base = base | 4 ;
}
2019-05-26 21:14:53 +03:00
if ( ! this . isPublicRoom ( ) ) {
2018-07-06 13:30:00 +00:00
base = base | 8 ;
}
2019-04-21 23:42:00 +00:00
2019-03-18 01:22:00 +00:00
message . appendInt ( base ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( this . getGuildId ( ) > 0 ) {
2018-07-06 13:30:00 +00:00
Guild g = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . getGuildId ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( g ! = null ) {
2018-07-06 13:30:00 +00:00
message . appendInt ( g . getId ( ) ) ;
message . appendString ( g . getName ( ) ) ;
message . appendString ( g . getBadge ( ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
message . appendInt ( 0 ) ;
message . appendString ( " " ) ;
message . appendString ( " " ) ;
}
}
2019-05-26 21:14:53 +03:00
if ( this . promoted ) {
2018-07-06 13:30:00 +00:00
message . appendString ( this . promotion . getTitle ( ) ) ;
message . appendString ( this . promotion . getDescription ( ) ) ;
message . appendInt ( ( this . promotion . getEndTimestamp ( ) - Emulator . getIntUnixTimestamp ( ) ) / 60 ) ;
}
}
@Override
2019-05-26 21:14:53 +03:00
public void run ( ) {
2018-07-06 13:30:00 +00:00
long millis = System . currentTimeMillis ( ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . loadLock ) {
if ( this . loaded ) {
try {
2018-07-06 13:30:00 +00:00
Emulator . getThreading ( ) . run (
2020-04-23 18:08:37 +01:00
Room . this : : cycle ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
this . save ( ) ;
}
2019-05-26 21:14:53 +03:00
public void save ( ) {
if ( this . needsUpdate ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ? WHERE id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setString ( 1 , this . name ) ;
statement . setString ( 2 , this . description ) ;
statement . setString ( 3 , this . password ) ;
statement . setString ( 4 , this . state . name ( ) . toLowerCase ( ) ) ;
statement . setInt ( 5 , this . usersMax ) ;
statement . setInt ( 6 , this . category ) ;
statement . setInt ( 7 , this . score ) ;
statement . setString ( 8 , this . floorPaint ) ;
statement . setString ( 9 , this . wallPaint ) ;
statement . setString ( 10 , this . backgroundPaint ) ;
statement . setInt ( 11 , this . wallSize ) ;
statement . setInt ( 12 , this . wallHeight ) ;
statement . setInt ( 13 , this . floorSize ) ;
2019-03-18 01:22:00 +00:00
StringBuilder moodLightData = new StringBuilder ( ) ;
2018-07-06 13:30:00 +00:00
int id = 1 ;
2019-05-26 21:14:53 +03:00
for ( RoomMoodlightData data : this . moodlightData . valueCollection ( ) ) {
2018-07-06 13:30:00 +00:00
data . setId ( id ) ;
2019-03-18 01:22:00 +00:00
moodLightData . append ( data . toString ( ) ) . append ( " ; " ) ;
2018-07-06 13:30:00 +00:00
id + + ;
}
2019-03-18 01:22:00 +00:00
statement . setString ( 14 , moodLightData . toString ( ) ) ;
2018-07-06 13:30:00 +00:00
statement . setString ( 15 , this . tags ) ;
statement . setString ( 16 , this . allowPets ? " 1 " : " 0 " ) ;
statement . setString ( 17 , this . allowPetsEat ? " 1 " : " 0 " ) ;
statement . setString ( 18 , this . allowWalkthrough ? " 1 " : " 0 " ) ;
statement . setString ( 19 , this . hideWall ? " 1 " : " 0 " ) ;
statement . setInt ( 20 , this . chatMode ) ;
statement . setInt ( 21 , this . chatWeight ) ;
statement . setInt ( 22 , this . chatSpeed ) ;
statement . setInt ( 23 , this . chatDistance ) ;
statement . setInt ( 24 , this . chatProtection ) ;
statement . setInt ( 25 , this . muteOption ) ;
statement . setInt ( 26 , this . kickOption ) ;
statement . setInt ( 27 , this . banOption ) ;
statement . setInt ( 28 , this . pollId ) ;
statement . setInt ( 29 , this . guild ) ;
statement . setInt ( 30 , this . rollerSpeed ) ;
statement . setString ( 31 , this . overrideModel ? " 1 " : " 0 " ) ;
statement . setString ( 32 , this . staffPromotedRoom ? " 1 " : " 0 " ) ;
statement . setString ( 33 , this . promoted ? " 1 " : " 0 " ) ;
statement . setInt ( 34 , this . tradeMode ) ;
statement . setString ( 35 , this . moveDiagonally ? " 1 " : " 0 " ) ;
statement . setInt ( 36 , this . ownerId ) ;
statement . setString ( 37 , this . ownerName ) ;
statement . setString ( 38 , this . jukeboxActive ? " 1 " : " 0 " ) ;
2018-09-28 19:25:00 +00:00
statement . setString ( 39 , this . hideWired ? " 1 " : " 0 " ) ;
statement . setInt ( 40 , this . id ) ;
2018-07-06 13:30:00 +00:00
statement . executeUpdate ( ) ;
this . needsUpdate = false ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
private void updateDatabaseUserCount ( ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE rooms SET users = ? WHERE id = ? LIMIT 1 " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . currentHabbos . size ( ) ) ;
statement . setInt ( 2 , this . id ) ;
statement . executeUpdate ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private void cycle ( ) {
2020-06-12 22:10:05 +02:00
this . cycleOdd = ! this . cycleOdd ;
2019-03-18 01:22:00 +00:00
this . cycleTimestamp = System . currentTimeMillis ( ) ;
2018-07-06 13:30:00 +00:00
final boolean [ ] foundRightHolder = { false } ;
2019-03-18 01:22:00 +00:00
boolean loaded ;
2019-05-26 21:14:53 +03:00
synchronized ( this . loadLock ) {
2018-07-06 13:30:00 +00:00
loaded = this . loaded ;
}
2018-11-17 13:28:00 +00:00
this . tileCache . clear ( ) ;
2019-05-26 21:14:53 +03:00
if ( loaded ) {
if ( ! this . scheduledTasks . isEmpty ( ) ) {
2018-07-06 13:30:00 +00:00
ConcurrentSet < Runnable > tasks = this . scheduledTasks ;
this . scheduledTasks = new ConcurrentSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( Runnable runnable : tasks ) {
2018-07-06 13:30:00 +00:00
Emulator . getThreading ( ) . run ( runnable ) ;
}
}
2019-05-26 21:14:53 +03:00
for ( ICycleable task : this . roomSpecialTypes . getCycleTasks ( ) ) {
2018-09-28 19:25:00 +00:00
task . cycle ( this ) ;
}
2019-05-26 21:14:53 +03:00
if ( ! this . currentHabbos . isEmpty ( ) ) {
2018-07-06 13:30:00 +00:00
this . idleCycles = 0 ;
2018-09-28 19:25:00 +00:00
THashSet < RoomUnit > updatedUnit = new THashSet < > ( ) ;
ArrayList < Habbo > toKick = new ArrayList < > ( ) ;
2018-07-06 13:30:00 +00:00
final Room room = this ;
final long millis = System . currentTimeMillis ( ) ;
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : this . currentHabbos . values ( ) ) {
if ( ! foundRightHolder [ 0 ] ) {
2018-07-06 13:30:00 +00:00
foundRightHolder [ 0 ] = habbo . getRoomUnit ( ) . getRightsLevel ( ) ! = RoomRightLevels . NONE ;
}
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . getHandItem ( ) > 0 & & millis - habbo . getRoomUnit ( ) . getHandItemTimestamp ( ) > ( Room . HAND_ITEM_TIME * 1000 ) ) {
2019-03-18 01:22:00 +00:00
this . giveHandItem ( habbo , 0 ) ;
}
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . getEffectId ( ) > 0 & & millis / 1000 > habbo . getRoomUnit ( ) . getEffectEndTimestamp ( ) ) {
2019-03-18 01:22:00 +00:00
this . giveEffect ( habbo , 0 , - 1 ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . isKicked ) {
2018-10-06 22:28:00 +00:00
habbo . getRoomUnit ( ) . kickCount + + ;
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . kickCount > = 5 ) {
2020-04-23 18:08:37 +01:00
this . scheduledTasks . add ( ( ) - > Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , room ) ) ;
2018-10-06 22:28:00 +00:00
continue ;
}
}
2019-05-26 21:14:53 +03:00
if ( Emulator . getConfig ( ) . getBoolean ( " hotel.rooms.auto.idle " ) ) {
if ( ! habbo . getRoomUnit ( ) . isIdle ( ) ) {
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . increaseIdleTimer ( ) ;
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . isIdle ( ) ) {
2019-03-18 01:22:00 +00:00
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2020-04-21 00:08:39 +01:00
WiredHandler . handle ( WiredTriggerType . IDLES , habbo . getRoomUnit ( ) , this , new Object [ ] { habbo } ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . increaseIdleTimer ( ) ;
2019-05-26 21:14:53 +03:00
if ( ! this . isOwner ( habbo ) & & habbo . getRoomUnit ( ) . getIdleTimer ( ) > = Room . IDLE_CYCLES_KICK ) {
2018-07-06 13:30:00 +00:00
UserExitRoomEvent event = new UserExitRoomEvent ( habbo , UserExitRoomEvent . UserExitRoomReason . KICKED_IDLE ) ;
Emulator . getPluginManager ( ) . fireEvent ( event ) ;
2019-05-26 21:14:53 +03:00
if ( ! event . isCancelled ( ) ) {
2018-07-06 13:30:00 +00:00
toKick . add ( habbo ) ;
}
}
}
}
2019-05-26 21:14:53 +03:00
if ( habbo . getHabboStats ( ) . mutedBubbleTracker & & habbo . getHabboStats ( ) . allowTalk ( ) ) {
2018-07-06 13:30:00 +00:00
habbo . getHabboStats ( ) . mutedBubbleTracker = false ;
this . sendComposer ( new RoomUserIgnoredComposer ( habbo , RoomUserIgnoredComposer . UNIGNORED ) . compose ( ) ) ;
}
2020-06-12 22:10:05 +02:00
// Substract 1 from the chatCounter every odd cycle, which is every (500ms * 2).
if ( this . cycleOdd & & habbo . getHabboStats ( ) . chatCounter . get ( ) > 0 ) {
habbo . getHabboStats ( ) . chatCounter . decrementAndGet ( ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
if ( this . cycleRoomUnit ( habbo . getRoomUnit ( ) , RoomUnitType . USER ) ) {
2018-09-12 16:45:00 +00:00
updatedUnit . add ( habbo . getRoomUnit ( ) ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
if ( ! toKick . isEmpty ( ) ) {
for ( Habbo habbo : toKick ) {
2018-07-06 13:30:00 +00:00
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
}
2019-05-26 21:14:53 +03:00
if ( ! this . currentBots . isEmpty ( ) ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
final Bot bot ;
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
botIterator . advance ( ) ;
bot = botIterator . value ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
2019-05-26 21:14:53 +03:00
if ( ! this . allowBotsWalk & & bot . getRoomUnit ( ) . isWalking ( ) ) {
2018-07-06 13:30:00 +00:00
bot . getRoomUnit ( ) . stopWalking ( ) ;
updatedUnit . add ( bot . getRoomUnit ( ) ) ;
continue ;
}
2019-04-21 23:42:00 +00:00
botIterator . value ( ) . cycle ( this . allowBotsWalk ) ;
2019-05-26 21:14:53 +03:00
if ( this . cycleRoomUnit ( bot . getRoomUnit ( ) , RoomUnitType . BOT ) ) {
2019-04-21 23:42:00 +00:00
updatedUnit . add ( bot . getRoomUnit ( ) ) ;
}
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2019-04-21 23:42:00 +00:00
break ;
}
}
}
2019-05-26 21:14:53 +03:00
if ( ! this . currentPets . isEmpty ( ) ) {
if ( this . allowBotsWalk ) {
2019-04-21 23:42:00 +00:00
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; ) {
try {
2019-04-21 23:42:00 +00:00
petIterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2019-04-21 23:42:00 +00:00
break ;
}
Pet pet = petIterator . value ( ) ;
2019-05-26 21:14:53 +03:00
if ( this . cycleRoomUnit ( pet . getRoomUnit ( ) , RoomUnitType . PET ) ) {
2019-04-21 23:42:00 +00:00
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
}
pet . cycle ( ) ;
2019-05-26 21:14:53 +03:00
if ( pet . packetUpdate ) {
2019-04-21 23:42:00 +00:00
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
pet . packetUpdate = false ;
}
2019-05-26 21:14:53 +03:00
if ( pet . getRoomUnit ( ) . isWalking ( ) & & pet . getRoomUnit ( ) . getPath ( ) . size ( ) = = 1 & & pet . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . GESTURE ) ) {
2019-04-21 23:42:00 +00:00
pet . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . GESTURE ) ;
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
}
}
}
}
2019-05-26 21:14:53 +03:00
if ( this . rollerSpeed ! = - 1 & & this . rollerCycle > = this . rollerSpeed ) {
2019-04-21 23:42:00 +00:00
this . rollerCycle = 0 ;
THashSet < MessageComposer > messages = new THashSet < > ( ) ;
//Find alternative for this.
//Reason is that tile gets updated after every roller.
List < Integer > rollerFurniIds = new ArrayList < > ( ) ;
List < Integer > rolledUnitIds = new ArrayList < > ( ) ;
2019-05-26 21:14:53 +03:00
2019-05-12 22:09:16 -04:00
this . roomSpecialTypes . getRollers ( ) . forEachValue ( roller - > {
2019-05-04 02:25:43 +01:00
2019-05-12 22:09:16 -04:00
HabboItem newRoller = null ;
2019-04-21 23:42:00 +00:00
2019-05-13 04:11:27 +01:00
RoomTile rollerTile = this . getLayout ( ) . getTile ( roller . getX ( ) , roller . getY ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( rollerTile = = null )
2019-05-13 04:11:27 +01:00
return true ;
2019-05-12 22:09:16 -04:00
THashSet < HabboItem > itemsOnRoller = new THashSet < > ( ) ;
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
for ( HabboItem item : getItemsAt ( rollerTile ) ) {
if ( item . getZ ( ) > = roller . getZ ( ) + Item . getCurrentHeight ( roller ) ) {
2019-05-13 03:31:21 +01:00
itemsOnRoller . add ( item ) ;
}
}
2019-05-26 21:14:53 +03:00
// itemsOnRoller.addAll(this.getItemsAt(rollerTile));
2019-05-12 22:09:16 -04:00
itemsOnRoller . remove ( roller ) ;
2019-04-21 23:42:00 +00:00
2019-05-13 04:11:27 +01:00
if ( ! rollerTile . hasUnits ( ) & & itemsOnRoller . isEmpty ( ) )
2019-05-12 22:09:16 -04:00
return true ;
2019-04-21 23:42:00 +00:00
2019-05-12 22:09:16 -04:00
RoomTile tileInFront = Room . this . layout . getTileInFront ( Room . this . layout . getTile ( roller . getX ( ) , roller . getY ( ) ) , roller . getRotation ( ) ) ;
2019-04-21 23:42:00 +00:00
2019-05-12 22:09:16 -04:00
if ( tileInFront = = null )
return true ;
2019-04-21 23:42:00 +00:00
2019-05-12 22:09:16 -04:00
if ( ! Room . this . layout . tileExists ( tileInFront . x , tileInFront . y ) )
return true ;
2019-04-21 23:42:00 +00:00
2019-05-12 22:09:16 -04:00
if ( tileInFront . state = = RoomTileState . INVALID )
return true ;
2019-05-04 02:25:43 +01:00
2019-05-12 22:09:16 -04:00
if ( ! tileInFront . getAllowStack ( ) & & ! ( tileInFront . isWalkable ( ) | | tileInFront . state = = RoomTileState . SIT | | tileInFront . state = = RoomTileState . LAY ) )
return true ;
2019-05-04 02:25:43 +01:00
2019-05-13 04:11:27 +01:00
if ( tileInFront . hasUnits ( ) )
2019-05-12 22:09:16 -04:00
return true ;
2019-05-12 11:03:40 -04:00
2019-05-12 22:09:16 -04:00
THashSet < HabboItem > itemsNewTile = new THashSet < > ( ) ;
itemsNewTile . addAll ( getItemsAt ( tileInFront ) ) ;
itemsNewTile . removeAll ( itemsOnRoller ) ;
2019-05-12 21:36:53 -04:00
2019-05-12 22:09:16 -04:00
List < HabboItem > toRemove = new ArrayList < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : itemsOnRoller ) {
if ( item . getX ( ) ! = roller . getX ( ) | | item . getY ( ) ! = roller . getY ( ) | | rollerFurniIds . contains ( item . getId ( ) ) ) {
2019-05-12 22:09:16 -04:00
toRemove . add ( item ) ;
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
}
itemsOnRoller . removeAll ( toRemove ) ;
HabboItem topItem = Room . this . getTopItemAt ( tileInFront . x , tileInFront . y ) ;
2019-05-12 21:36:53 -04:00
2019-05-12 22:09:16 -04:00
boolean allowUsers = true ;
boolean allowFurniture = true ;
boolean stackContainsRoller = false ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : itemsNewTile ) {
if ( ! ( item . getBaseItem ( ) . allowWalk ( ) | | item . getBaseItem ( ) . allowSit ( ) ) & & ! ( item instanceof InteractionGate & & item . getExtradata ( ) . equals ( " 1 " ) ) ) {
2019-05-12 22:09:16 -04:00
allowUsers = false ;
2019-05-12 21:36:53 -04:00
}
2019-05-26 21:14:53 +03:00
if ( item instanceof InteractionRoller ) {
2019-05-12 22:09:16 -04:00
newRoller = item ;
stackContainsRoller = true ;
2019-05-12 21:36:53 -04:00
2019-05-26 21:14:53 +03:00
if ( ( item . getZ ( ) ! = roller . getZ ( ) | | ( itemsNewTile . size ( ) > 1 & & item ! = topItem ) ) & & ! InteractionRoller . NO_RULES ) {
2019-05-12 22:09:16 -04:00
allowUsers = false ;
2019-04-21 23:42:00 +00:00
allowFurniture = false ;
2019-05-12 22:09:16 -04:00
continue ;
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
break ;
2019-05-26 21:14:53 +03:00
} else {
2019-05-12 22:09:16 -04:00
allowFurniture = false ;
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
}
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( allowFurniture ) {
2019-05-12 22:09:16 -04:00
allowFurniture = tileInFront . getAllowStack ( ) ;
}
double zOffset = 0 ;
2019-05-26 21:14:53 +03:00
if ( newRoller ! = null ) {
if ( ( ! itemsNewTile . isEmpty ( ) & & ( itemsNewTile . size ( ) > 1 ) ) & & ! InteractionRoller . NO_RULES ) {
2019-05-12 22:09:16 -04:00
return true ;
2019-04-21 23:42:00 +00:00
}
2019-05-26 21:14:53 +03:00
} else {
2019-05-12 22:09:16 -04:00
zOffset = - Item . getCurrentHeight ( roller ) + tileInFront . getStackHeight ( ) - rollerTile . z ;
}
2019-05-26 21:14:53 +03:00
if ( allowUsers ) {
2019-05-12 22:09:16 -04:00
Event roomUserRolledEvent = null ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( UserRolledEvent . class , true ) ) {
2019-05-12 22:09:16 -04:00
roomUserRolledEvent = new UserRolledEvent ( null , null , null ) ;
2019-04-21 23:42:00 +00:00
}
2020-10-08 12:34:14 -05:00
ArrayList < RoomUnit > unitsOnTile = new ArrayList < > ( rollerTile . getUnits ( ) ) ;
2019-05-12 11:03:40 -04:00
2019-05-26 21:14:53 +03:00
for ( RoomUnit unit : rollerTile . getUnits ( ) ) {
if ( unit . getRoomUnitType ( ) = = RoomUnitType . PET ) {
2019-05-13 04:11:27 +01:00
Pet pet = this . getPet ( unit ) ;
if ( pet instanceof RideablePet & & ( ( RideablePet ) pet ) . getRider ( ) ! = null ) {
unitsOnTile . remove ( unit ) ;
}
}
}
2020-10-15 08:35:59 +02:00
HabboItem nextTileChair = this . getTallestChair ( tileInFront ) ;
2019-05-16 12:41:14 +01:00
2020-09-01 20:47:49 +02:00
THashSet < Integer > usersRolledThisTile = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( RoomUnit unit : unitsOnTile ) {
2019-05-13 04:11:27 +01:00
if ( rolledUnitIds . contains ( unit . getId ( ) ) ) continue ;
2019-05-12 22:09:16 -04:00
2020-09-01 20:47:49 +02:00
if ( usersRolledThisTile . size ( ) > = Room . ROLLERS_MAXIMUM_ROLL_AVATARS ) break ;
2019-05-12 22:09:16 -04:00
if ( stackContainsRoller & & ! allowFurniture & & ! ( topItem ! = null & & topItem . isWalkable ( ) ) )
continue ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( unit . hasStatus ( RoomUnitStatus . MOVE ) )
2019-05-13 04:11:27 +01:00
continue ;
2018-07-06 13:30:00 +00:00
2019-05-13 04:11:27 +01:00
RoomTile tile = tileInFront . copy ( ) ;
tile . setStackHeight ( unit . getZ ( ) + zOffset ) ;
2018-09-12 16:45:00 +00:00
2019-05-26 21:14:53 +03:00
if ( roomUserRolledEvent ! = null & & unit . getRoomUnitType ( ) = = RoomUnitType . USER ) {
2019-05-13 04:11:27 +01:00
roomUserRolledEvent = new UserRolledEvent ( getHabbo ( unit ) , roller , tile ) ;
Emulator . getPluginManager ( ) . fireEvent ( roomUserRolledEvent ) ;
2018-07-06 13:30:00 +00:00
2019-05-13 04:11:27 +01:00
if ( roomUserRolledEvent . isCancelled ( ) )
continue ;
}
2018-09-28 19:25:00 +00:00
2019-05-13 04:11:27 +01:00
// horse riding
boolean isRiding = false ;
2019-05-26 21:14:53 +03:00
if ( unit . getRoomUnitType ( ) = = RoomUnitType . USER ) {
2019-05-13 04:11:27 +01:00
Habbo rollingHabbo = this . getHabbo ( unit ) ;
2019-05-26 21:14:53 +03:00
if ( rollingHabbo ! = null & & rollingHabbo . getHabboInfo ( ) ! = null ) {
2019-05-17 07:33:30 +01:00
RideablePet riding = rollingHabbo . getHabboInfo ( ) . getRiding ( ) ;
if ( riding ! = null ) {
RoomUnit ridingUnit = riding . getRoomUnit ( ) ;
tile . setStackHeight ( ridingUnit . getZ ( ) + zOffset ) ;
rolledUnitIds . add ( ridingUnit . getId ( ) ) ;
updatedUnit . remove ( ridingUnit ) ;
2020-10-16 05:50:57 +02:00
messages . add ( new RoomUnitOnRollerComposer ( ridingUnit , roller , ridingUnit . getCurrentLocation ( ) , ridingUnit . getZ ( ) , tile , tile . getStackHeight ( ) , room ) ) ;
2019-05-17 07:33:30 +01:00
isRiding = true ;
}
2019-05-12 22:09:16 -04:00
}
}
2019-05-12 11:03:40 -04:00
2020-09-01 20:47:49 +02:00
usersRolledThisTile . add ( unit . getId ( ) ) ;
2019-05-13 04:11:27 +01:00
rolledUnitIds . add ( unit . getId ( ) ) ;
updatedUnit . remove ( unit ) ;
2020-10-16 05:50:57 +02:00
messages . add ( new RoomUnitOnRollerComposer ( unit , roller , unit . getCurrentLocation ( ) , unit . getZ ( ) + ( isRiding ? 1 : 0 ) , tile , tile . getStackHeight ( ) + ( isRiding ? 1 : 0 ) , room ) ) ;
2019-05-12 11:03:40 -04:00
2019-05-26 21:14:53 +03:00
if ( itemsOnRoller . isEmpty ( ) ) {
2019-05-13 04:11:27 +01:00
HabboItem item = room . getTopItemAt ( tileInFront . x , tileInFront . y ) ;
2019-05-12 21:36:53 -04:00
2020-10-12 11:18:52 +02:00
if ( item ! = null & & itemsNewTile . contains ( item ) & & ! itemsOnRoller . contains ( item ) ) {
2020-04-23 18:08:37 +01:00
Emulator . getThreading ( ) . run ( ( ) - > {
if ( unit . getGoal ( ) = = rollerTile ) {
try {
2020-10-15 08:35:59 +02:00
item . onWalkOn ( unit , room , new Object [ ] { rollerTile , tileInFront } ) ;
2020-04-23 18:08:37 +01:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2019-05-16 10:27:06 +01:00
}
}
2020-01-31 11:52:37 -05:00
} , this . getRollerSpeed ( ) = = 0 ? 250 : InteractionRoller . DELAY ) ;
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
}
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( unit . hasStatus ( RoomUnitStatus . SIT ) ) {
2019-05-13 04:11:27 +01:00
unit . sitUpdate = true ;
}
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
}
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ! messages . isEmpty ( ) ) {
for ( MessageComposer message : messages ) {
2019-05-12 22:09:16 -04:00
room . sendComposer ( message . compose ( ) ) ;
2019-03-18 01:22:00 +00:00
}
2019-05-12 22:09:16 -04:00
messages . clear ( ) ;
}
2018-09-28 19:25:00 +00:00
2019-05-26 21:14:53 +03:00
if ( allowFurniture | | ! stackContainsRoller | | InteractionRoller . NO_RULES ) {
2019-05-12 22:09:16 -04:00
Event furnitureRolledEvent = null ;
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureRolledEvent . class , true ) ) {
2019-05-12 22:09:16 -04:00
furnitureRolledEvent = new FurnitureRolledEvent ( null , null , null ) ;
}
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( newRoller = = null | | topItem = = newRoller ) {
2019-05-12 22:09:16 -04:00
List < HabboItem > sortedItems = new ArrayList < > ( itemsOnRoller ) ;
2019-08-30 02:25:54 +01:00
sortedItems . sort ( ( o1 , o2 ) - > o1 . getZ ( ) > o2 . getZ ( ) ? - 1 : 1 ) ;
2019-05-12 21:36:53 -04:00
2019-05-26 21:14:53 +03:00
for ( HabboItem item : sortedItems ) {
if ( item . getX ( ) = = roller . getX ( ) & & item . getY ( ) = = roller . getY ( ) & & zOffset < = 0 ) {
if ( item ! = roller ) {
if ( furnitureRolledEvent ! = null ) {
2019-05-12 22:09:16 -04:00
furnitureRolledEvent = new FurnitureRolledEvent ( item , roller , tileInFront ) ;
Emulator . getPluginManager ( ) . fireEvent ( furnitureRolledEvent ) ;
2019-04-21 23:42:00 +00:00
2019-05-12 22:09:16 -04:00
if ( furnitureRolledEvent . isCancelled ( ) )
continue ;
2019-05-12 21:36:53 -04:00
}
2019-05-12 22:09:16 -04:00
messages . add ( new FloorItemOnRollerComposer ( item , roller , tileInFront , zOffset , room ) ) ;
rollerFurniIds . add ( item . getId ( ) ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-03-18 01:22:00 +00:00
}
2019-05-12 22:09:16 -04:00
}
2018-07-06 13:30:00 +00:00
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ! messages . isEmpty ( ) ) {
for ( MessageComposer message : messages ) {
2019-05-12 22:09:16 -04:00
room . sendComposer ( message . compose ( ) ) ;
2019-04-21 23:42:00 +00:00
}
2019-05-12 22:09:16 -04:00
messages . clear ( ) ;
2019-05-12 21:36:53 -04:00
}
2019-05-12 22:09:16 -04:00
return true ;
2019-04-21 23:42:00 +00:00
} ) ;
int currentTime = ( int ) ( this . cycleTimestamp / 1000 ) ;
2019-05-26 21:14:53 +03:00
for ( HabboItem pyramid : this . roomSpecialTypes . getItemsOfType ( InteractionPyramid . class ) ) {
if ( pyramid instanceof InteractionPyramid ) {
2019-04-21 23:42:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ( ( InteractionPyramid ) pyramid ) . getNextChange ( ) < currentTime ) {
2019-04-21 23:42:00 +00:00
( ( InteractionPyramid ) pyramid ) . change ( this ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
} else {
2019-04-21 23:42:00 +00:00
this . rollerCycle + + ;
}
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ! updatedUnit . isEmpty ( ) ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RoomUserStatusComposer ( updatedUnit , true ) . compose ( ) ) ;
}
this . traxManager . cycle ( ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( this . idleCycles < 60 )
2018-07-06 13:30:00 +00:00
this . idleCycles + + ;
else
this . dispose ( ) ;
}
}
2019-05-26 21:14:53 +03:00
synchronized ( this . habboQueue ) {
if ( ! this . habboQueue . isEmpty ( ) & & ! foundRightHolder [ 0 ] ) {
this . habboQueue . forEachEntry ( new TIntObjectProcedure < Habbo > ( ) {
2018-07-06 13:30:00 +00:00
@Override
2019-05-26 21:14:53 +03:00
public boolean execute ( int a , Habbo b ) {
if ( b . isOnline ( ) ) {
if ( b . getHabboInfo ( ) . getRoomQueueId ( ) = = Room . this . getId ( ) ) {
2018-07-06 13:30:00 +00:00
b . getClient ( ) . sendResponse ( new RoomAccessDeniedComposer ( " " ) ) ;
}
}
return true ;
}
} ) ;
this . habboQueue . clear ( ) ;
}
}
2019-05-26 21:14:53 +03:00
if ( ! this . scheduledComposers . isEmpty ( ) ) {
for ( ServerMessage message : this . scheduledComposers ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( message ) ;
}
this . scheduledComposers . clear ( ) ;
}
}
2018-09-12 16:45:00 +00:00
2019-05-26 21:14:53 +03:00
private boolean cycleRoomUnit ( RoomUnit unit , RoomUnitType type ) {
2018-09-28 19:25:00 +00:00
boolean update = unit . needsStatusUpdate ( ) ;
2019-05-26 21:14:53 +03:00
if ( unit . hasStatus ( RoomUnitStatus . SIGN ) ) {
2019-03-18 01:22:00 +00:00
this . sendComposer ( new RoomUserStatusComposer ( unit ) . compose ( ) ) ;
2018-09-12 16:45:00 +00:00
unit . removeStatus ( RoomUnitStatus . SIGN ) ;
}
2019-05-26 21:14:53 +03:00
if ( unit . isWalking ( ) & & unit . getPath ( ) ! = null & & ! unit . getPath ( ) . isEmpty ( ) ) {
if ( ! unit . cycle ( this ) ) {
2018-09-12 16:45:00 +00:00
return true ;
}
2019-05-26 21:14:53 +03:00
} else {
if ( unit . hasStatus ( RoomUnitStatus . MOVE ) & & ! unit . animateWalk ) {
2018-09-12 16:45:00 +00:00
unit . removeStatus ( RoomUnitStatus . MOVE ) ;
update = true ;
}
2019-05-26 21:14:53 +03:00
if ( ! unit . isWalking ( ) & & ! unit . cmdSit ) {
2020-10-15 08:35:59 +02:00
RoomTile thisTile = this . getLayout ( ) . getTile ( unit . getX ( ) , unit . getY ( ) ) ;
HabboItem topItem = this . getTallestChair ( thisTile ) ;
2018-09-12 16:45:00 +00:00
2019-05-26 21:14:53 +03:00
if ( topItem = = null | | ! topItem . getBaseItem ( ) . allowSit ( ) ) {
if ( unit . hasStatus ( RoomUnitStatus . SIT ) ) {
2018-09-12 16:45:00 +00:00
unit . removeStatus ( RoomUnitStatus . SIT ) ;
update = true ;
}
2020-10-15 08:35:59 +02:00
} else if ( thisTile . state = = RoomTileState . SIT & & ( ! unit . hasStatus ( RoomUnitStatus . SIT ) | | unit . sitUpdate ) ) {
this . dance ( unit , DanceType . NONE ) ;
//int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
unit . setStatus ( RoomUnitStatus . SIT , ( Item . getCurrentHeight ( topItem ) * 1 . 0D ) + " " ) ;
unit . setZ ( topItem . getZ ( ) ) ;
unit . setRotation ( RoomUserRotation . values ( ) [ topItem . getRotation ( ) ] ) ;
unit . sitUpdate = false ;
return true ;
2018-09-12 16:45:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
if ( ! unit . isWalking ( ) & & ! unit . cmdLay ) {
2019-03-18 01:22:00 +00:00
HabboItem topItem = this . getTopItemAt ( unit . getX ( ) , unit . getY ( ) ) ;
2018-09-12 16:45:00 +00:00
2019-05-26 21:14:53 +03:00
if ( topItem = = null | | ! topItem . getBaseItem ( ) . allowLay ( ) ) {
if ( unit . hasStatus ( RoomUnitStatus . LAY ) ) {
2018-09-12 16:45:00 +00:00
unit . removeStatus ( RoomUnitStatus . LAY ) ;
update = true ;
}
2019-05-26 21:14:53 +03:00
} else {
if ( ! unit . hasStatus ( RoomUnitStatus . LAY ) ) {
2019-05-12 08:59:01 +01:00
unit . setStatus ( RoomUnitStatus . LAY , Item . getCurrentHeight ( topItem ) * 1 . 0D + " " ) ;
2018-09-12 16:45:00 +00:00
unit . setRotation ( RoomUserRotation . values ( ) [ topItem . getRotation ( ) ] ) ;
2019-05-26 21:14:53 +03:00
if ( topItem . getRotation ( ) = = 0 | | topItem . getRotation ( ) = = 4 ) {
2019-03-18 01:22:00 +00:00
unit . setLocation ( this . layout . getTile ( unit . getX ( ) , topItem . getY ( ) ) ) ;
2018-09-12 16:45:00 +00:00
//unit.setOldY(topItem.getY());
2019-05-26 21:14:53 +03:00
} else {
2019-03-18 01:22:00 +00:00
unit . setLocation ( this . layout . getTile ( topItem . getX ( ) , unit . getY ( ) ) ) ;
2018-09-12 16:45:00 +00:00
//unit.setOldX(topItem.getX());
}
update = true ;
}
}
}
2019-05-26 21:14:53 +03:00
if ( update ) {
2018-09-28 19:25:00 +00:00
unit . statusUpdate ( false ) ;
}
2018-09-12 16:45:00 +00:00
return update ;
}
2019-05-26 21:14:53 +03:00
public int getId ( ) {
2018-07-06 13:30:00 +00:00
return this . id ;
}
2019-05-26 21:14:53 +03:00
public int getOwnerId ( ) {
2018-07-06 13:30:00 +00:00
return this . ownerId ;
}
2019-05-26 21:14:53 +03:00
public void setOwnerId ( int ownerId ) {
2018-07-06 13:30:00 +00:00
this . ownerId = ownerId ;
}
2019-05-26 21:14:53 +03:00
public String getOwnerName ( ) {
2018-07-06 13:30:00 +00:00
return this . ownerName ;
}
2019-05-26 21:14:53 +03:00
public void setOwnerName ( String ownerName ) {
2018-07-06 13:30:00 +00:00
this . ownerName = ownerName ;
}
2019-05-26 21:14:53 +03:00
public String getName ( ) {
2018-07-06 13:30:00 +00:00
return this . name ;
}
2019-05-26 21:14:53 +03:00
public void setName ( String name ) {
this . name = name ;
if ( this . name . length ( ) > 50 ) {
this . name = this . name . substring ( 0 , 50 ) ;
}
if ( this . hasGuild ( ) ) {
Guild guild = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . guild ) ;
if ( guild ! = null ) {
guild . setRoomName ( name ) ;
}
}
}
public String getDescription ( ) {
2018-07-06 13:30:00 +00:00
return this . description ;
}
2019-05-26 21:14:53 +03:00
public void setDescription ( String description ) {
this . description = description ;
if ( this . description . length ( ) > 250 ) {
this . description = this . description . substring ( 0 , 250 ) ;
}
}
public RoomLayout getLayout ( ) {
2018-07-06 13:30:00 +00:00
return this . layout ;
}
2019-05-26 21:14:53 +03:00
public void setLayout ( RoomLayout layout ) {
2018-07-06 13:30:00 +00:00
this . layout = layout ;
}
2019-05-26 21:14:53 +03:00
public boolean hasCustomLayout ( ) {
2018-07-06 13:30:00 +00:00
return this . overrideModel ;
}
2019-05-26 21:14:53 +03:00
public void setHasCustomLayout ( boolean overrideModel ) {
2018-07-06 13:30:00 +00:00
this . overrideModel = overrideModel ;
}
2019-05-26 21:14:53 +03:00
public String getPassword ( ) {
2018-07-06 13:30:00 +00:00
return this . password ;
}
2019-05-26 21:14:53 +03:00
public void setPassword ( String password ) {
this . password = password ;
if ( this . password . length ( ) > 20 ) {
this . password = this . password . substring ( 0 , 20 ) ;
}
}
public RoomState getState ( ) {
2018-07-06 13:30:00 +00:00
return this . state ;
}
2019-05-26 21:14:53 +03:00
public void setState ( RoomState state ) {
this . state = state ;
}
public int getUsersMax ( ) {
2018-07-06 13:30:00 +00:00
return this . usersMax ;
}
2019-05-26 21:14:53 +03:00
public void setUsersMax ( int usersMax ) {
this . usersMax = usersMax ;
}
public int getScore ( ) {
2018-07-06 13:30:00 +00:00
return this . score ;
}
2019-05-26 21:14:53 +03:00
public void setScore ( int score ) {
this . score = score ;
}
public int getCategory ( ) {
2018-07-06 13:30:00 +00:00
return this . category ;
}
2019-05-26 21:14:53 +03:00
public void setCategory ( int category ) {
this . category = category ;
}
public String getFloorPaint ( ) {
2018-07-06 13:30:00 +00:00
return this . floorPaint ;
}
2019-05-26 21:14:53 +03:00
public void setFloorPaint ( String floorPaint ) {
this . floorPaint = floorPaint ;
}
public String getWallPaint ( ) {
2018-07-06 13:30:00 +00:00
return this . wallPaint ;
}
2019-05-26 21:14:53 +03:00
public void setWallPaint ( String wallPaint ) {
this . wallPaint = wallPaint ;
}
public String getBackgroundPaint ( ) {
2018-07-06 13:30:00 +00:00
return this . backgroundPaint ;
}
2019-05-26 21:14:53 +03:00
public void setBackgroundPaint ( String backgroundPaint ) {
this . backgroundPaint = backgroundPaint ;
}
public int getWallSize ( ) {
2018-07-06 13:30:00 +00:00
return this . wallSize ;
}
2019-05-26 21:14:53 +03:00
public void setWallSize ( int wallSize ) {
this . wallSize = wallSize ;
}
public int getWallHeight ( ) {
2018-07-06 13:30:00 +00:00
return this . wallHeight ;
}
2019-05-26 21:14:53 +03:00
public void setWallHeight ( int wallHeight ) {
2018-07-06 13:30:00 +00:00
this . wallHeight = wallHeight ;
}
2019-05-26 21:14:53 +03:00
public int getFloorSize ( ) {
2018-07-06 13:30:00 +00:00
return this . floorSize ;
}
2019-05-26 21:14:53 +03:00
public void setFloorSize ( int floorSize ) {
this . floorSize = floorSize ;
}
public String getTags ( ) {
2018-07-06 13:30:00 +00:00
return this . tags ;
}
2019-05-26 21:14:53 +03:00
public void setTags ( String tags ) {
this . tags = tags ;
}
public int getTradeMode ( ) {
2018-07-06 13:30:00 +00:00
return this . tradeMode ;
}
2019-05-26 21:14:53 +03:00
public void setTradeMode ( int tradeMode ) {
this . tradeMode = tradeMode ;
}
public boolean moveDiagonally ( ) {
2018-07-06 13:30:00 +00:00
return this . moveDiagonally ;
}
2019-05-26 21:14:53 +03:00
public void moveDiagonally ( boolean moveDiagonally ) {
2018-07-06 13:30:00 +00:00
this . moveDiagonally = moveDiagonally ;
this . layout . moveDiagonally ( this . moveDiagonally ) ;
this . needsUpdate = true ;
}
2019-05-26 21:14:53 +03:00
public int getGuildId ( ) {
2018-07-06 13:30:00 +00:00
return this . guild ;
}
2019-05-26 21:14:53 +03:00
public boolean hasGuild ( ) {
2018-07-06 13:30:00 +00:00
return this . guild ! = 0 ;
}
2019-05-26 21:14:53 +03:00
public void setGuild ( int guild ) {
2018-07-06 13:30:00 +00:00
this . guild = guild ;
}
2019-05-26 21:14:53 +03:00
public String getGuildName ( ) {
if ( this . hasGuild ( ) ) {
2018-07-06 13:30:00 +00:00
Guild guild = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . guild ) ;
2019-05-26 21:14:53 +03:00
if ( guild ! = null ) {
2018-07-06 13:30:00 +00:00
return guild . getName ( ) ;
}
}
return " " ;
}
2019-05-26 21:14:53 +03:00
public boolean isPublicRoom ( ) {
2018-07-06 13:30:00 +00:00
return this . publicRoom ;
}
2019-05-26 21:14:53 +03:00
public void setPublicRoom ( boolean publicRoom ) {
2018-12-22 10:39:00 +00:00
this . publicRoom = publicRoom ;
}
2019-05-26 21:14:53 +03:00
public boolean isStaffPromotedRoom ( ) {
2018-07-06 13:30:00 +00:00
return this . staffPromotedRoom ;
}
2019-05-26 21:14:53 +03:00
public void setStaffPromotedRoom ( boolean staffPromotedRoom ) {
2018-07-06 13:30:00 +00:00
this . staffPromotedRoom = staffPromotedRoom ;
}
2019-05-26 21:14:53 +03:00
public boolean isAllowPets ( ) {
2018-07-06 13:30:00 +00:00
return this . allowPets ;
}
2019-05-26 21:14:53 +03:00
public void setAllowPets ( boolean allowPets ) {
this . allowPets = allowPets ;
if ( ! allowPets ) {
removeAllPets ( ownerId ) ;
}
}
public boolean isAllowPetsEat ( ) {
2018-07-06 13:30:00 +00:00
return this . allowPetsEat ;
}
2019-05-26 21:14:53 +03:00
public void setAllowPetsEat ( boolean allowPetsEat ) {
this . allowPetsEat = allowPetsEat ;
}
public boolean isAllowWalkthrough ( ) {
2018-07-06 13:30:00 +00:00
return this . allowWalkthrough ;
}
2019-05-26 21:14:53 +03:00
public void setAllowWalkthrough ( boolean allowWalkthrough ) {
this . allowWalkthrough = allowWalkthrough ;
}
public boolean isAllowBotsWalk ( ) {
return this . allowBotsWalk ;
}
public void setAllowBotsWalk ( boolean allowBotsWalk ) {
this . allowBotsWalk = allowBotsWalk ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean isAllowEffects ( ) {
2018-07-06 13:30:00 +00:00
return this . allowEffects ;
}
2019-05-26 21:14:53 +03:00
public void setAllowEffects ( boolean allowEffects ) {
2018-07-06 13:30:00 +00:00
this . allowEffects = allowEffects ;
}
2019-05-26 21:14:53 +03:00
public boolean isHideWall ( ) {
2018-07-06 13:30:00 +00:00
return this . hideWall ;
}
2019-05-26 21:14:53 +03:00
public void setHideWall ( boolean hideWall ) {
this . hideWall = hideWall ;
}
public Color getBackgroundTonerColor ( ) {
2018-07-06 13:30:00 +00:00
Color color = new Color ( 0 , 0 , 0 ) ;
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i > 0 ; i - - ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
HabboItem object = iterator . value ( ) ;
2019-05-26 21:14:53 +03:00
if ( object instanceof InteractionBackgroundToner ) {
2018-07-06 13:30:00 +00:00
String [ ] extraData = object . getExtradata ( ) . split ( " : " ) ;
2019-05-26 21:14:53 +03:00
if ( extraData . length = = 4 ) {
if ( extraData [ 0 ] . equalsIgnoreCase ( " 1 " ) ) {
2020-10-08 12:34:14 -05:00
return Color . getHSBColor ( Integer . parseInt ( extraData [ 1 ] ) , Integer . parseInt ( extraData [ 2 ] ) , Integer . parseInt ( extraData [ 3 ] ) ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
}
}
return color ;
}
2019-05-26 21:14:53 +03:00
public int getChatMode ( ) {
2018-07-06 13:30:00 +00:00
return this . chatMode ;
}
2019-05-26 21:14:53 +03:00
public void setChatMode ( int chatMode ) {
this . chatMode = chatMode ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public int getChatWeight ( ) {
return this . chatWeight ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void setChatWeight ( int chatWeight ) {
this . chatWeight = chatWeight ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public int getChatSpeed ( ) {
return this . chatSpeed ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void setChatSpeed ( int chatSpeed ) {
this . chatSpeed = chatSpeed ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public int getChatDistance ( ) {
return this . chatDistance ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void setChatDistance ( int chatDistance ) {
this . chatDistance = chatDistance ;
2019-05-06 05:23:51 +01:00
}
public void removeAllPets ( ) {
removeAllPets ( - 1 ) ;
}
/ * *
* Removes all pets from the room except if the owner id is excludeUserId
2019-05-26 21:14:53 +03:00
*
2019-05-06 05:23:51 +01:00
* @param excludeUserId Habbo id to keep pets
* /
public void removeAllPets ( int excludeUserId ) {
2020-05-05 13:59:12 +02:00
ArrayList < Pet > toRemovePets = new ArrayList < > ( ) ;
2019-05-06 05:23:51 +01:00
ArrayList < Pet > removedPets = new ArrayList < > ( ) ;
synchronized ( this . currentPets ) {
for ( Pet pet : this . currentPets . valueCollection ( ) ) {
try {
if ( pet . getUserId ( ) ! = excludeUserId ) {
2020-05-05 13:59:12 +02:00
toRemovePets . add ( pet ) ;
2019-05-06 05:23:51 +01:00
}
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2019-05-06 05:23:51 +01:00
break ;
}
}
}
2020-05-05 13:59:12 +02:00
for ( Pet pet : toRemovePets ) {
removedPets . add ( pet ) ;
pet . removeFromRoom ( ) ;
Habbo habbo = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( pet . getUserId ( ) ) ;
if ( habbo ! = null ) {
habbo . getInventory ( ) . getPetsComponent ( ) . addPet ( pet ) ;
habbo . getClient ( ) . sendResponse ( new AddPetComposer ( pet ) ) ;
}
pet . needsUpdate = true ;
pet . run ( ) ;
}
2019-05-06 05:23:51 +01:00
for ( Pet pet : removedPets ) {
this . currentPets . remove ( pet . getId ( ) ) ;
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public int getChatProtection ( ) {
2018-07-06 13:30:00 +00:00
return this . chatProtection ;
}
2019-05-26 21:14:53 +03:00
public void setChatProtection ( int chatProtection ) {
2018-07-06 13:30:00 +00:00
this . chatProtection = chatProtection ;
}
2019-05-26 21:14:53 +03:00
public int getMuteOption ( ) {
2018-07-06 13:30:00 +00:00
return this . muteOption ;
}
2019-05-26 21:14:53 +03:00
public void setMuteOption ( int muteOption ) {
2018-07-06 13:30:00 +00:00
this . muteOption = muteOption ;
}
2019-05-26 21:14:53 +03:00
public int getKickOption ( ) {
2018-07-06 13:30:00 +00:00
return this . kickOption ;
}
2019-05-26 21:14:53 +03:00
public void setKickOption ( int kickOption ) {
2018-07-06 13:30:00 +00:00
this . kickOption = kickOption ;
}
2019-05-26 21:14:53 +03:00
public int getBanOption ( ) {
2018-07-06 13:30:00 +00:00
return this . banOption ;
}
2019-05-26 21:14:53 +03:00
public void setBanOption ( int banOption ) {
2018-07-06 13:30:00 +00:00
this . banOption = banOption ;
}
2019-05-26 21:14:53 +03:00
public int getPollId ( ) {
2018-07-06 13:30:00 +00:00
return this . pollId ;
}
2019-05-26 21:14:53 +03:00
public void setPollId ( int pollId ) {
this . pollId = pollId ;
}
public int getRollerSpeed ( ) {
2018-07-06 13:30:00 +00:00
return this . rollerSpeed ;
}
2019-05-26 21:14:53 +03:00
public void setRollerSpeed ( int rollerSpeed ) {
this . rollerSpeed = rollerSpeed ;
this . rollerCycle = 0 ;
this . needsUpdate = true ;
}
public String [ ] filterAnything ( ) {
2019-03-18 01:22:00 +00:00
return new String [ ] { this . getOwnerName ( ) , this . getGuildName ( ) , this . getDescription ( ) , this . getPromotionDesc ( ) } ;
}
2019-05-26 21:14:53 +03:00
public long getCycleTimestamp ( ) {
2019-03-18 01:22:00 +00:00
return this . cycleTimestamp ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean isPromoted ( ) {
2018-07-06 13:30:00 +00:00
this . promoted = this . promotion ! = null & & this . promotion . getEndTimestamp ( ) > Emulator . getIntUnixTimestamp ( ) ;
this . needsUpdate = true ;
return this . promoted ;
}
2019-05-26 21:14:53 +03:00
public RoomPromotion getPromotion ( ) {
2018-07-06 13:30:00 +00:00
return this . promotion ;
}
2019-05-26 21:14:53 +03:00
public String getPromotionDesc ( ) {
if ( this . promotion ! = null ) {
2018-07-06 13:30:00 +00:00
return this . promotion . getDescription ( ) ;
}
return " " ;
}
2020-01-27 20:45:44 +02:00
public void createPromotion ( String title , String description , int category ) {
2018-07-06 13:30:00 +00:00
this . promoted = true ;
2019-05-26 21:14:53 +03:00
if ( this . promotion = = null ) {
2020-01-27 20:45:44 +02:00
this . promotion = new RoomPromotion ( this , title , description , Emulator . getIntUnixTimestamp ( ) + ( 120 * 60 ) , Emulator . getIntUnixTimestamp ( ) , category ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
this . promotion . setTitle ( title ) ;
this . promotion . setDescription ( description ) ;
this . promotion . setEndTimestamp ( Emulator . getIntUnixTimestamp ( ) + ( 120 * 60 ) ) ;
2020-01-27 20:45:44 +02:00
this . promotion . setCategory ( category ) ;
2018-07-06 13:30:00 +00:00
}
2020-01-27 20:45:44 +02:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO room_promotions (room_id, title, description, end_timestamp, start_timestamp, category) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?, category = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
statement . setString ( 2 , title ) ;
statement . setString ( 3 , description ) ;
statement . setInt ( 4 , this . promotion . getEndTimestamp ( ) ) ;
2020-01-27 20:45:44 +02:00
statement . setInt ( 5 , this . promotion . getStartTimestamp ( ) ) ;
statement . setInt ( 6 , category ) ;
statement . setString ( 7 , this . promotion . getTitle ( ) ) ;
statement . setString ( 8 , this . promotion . getDescription ( ) ) ;
statement . setInt ( 9 , this . promotion . getEndTimestamp ( ) ) ;
statement . setInt ( 10 , this . promotion . getCategory ( ) ) ;
2018-07-06 13:30:00 +00:00
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
this . needsUpdate = true ;
}
2019-05-26 21:14:53 +03:00
public boolean addGame ( Game game ) {
synchronized ( this . games ) {
2018-07-06 13:30:00 +00:00
return this . games . add ( game ) ;
}
}
2019-05-26 21:14:53 +03:00
public boolean deleteGame ( Game game ) {
2018-07-06 13:30:00 +00:00
game . stop ( ) ;
2019-07-30 17:51:27 +03:00
game . dispose ( ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . games ) {
2018-07-06 13:30:00 +00:00
return this . games . remove ( game ) ;
}
}
2019-05-26 21:14:53 +03:00
public Game getGame ( Class < ? extends Game > gameType ) {
2019-07-30 14:03:50 +03:00
if ( gameType = = null ) return null ;
2019-05-26 21:14:53 +03:00
synchronized ( this . games ) {
for ( Game game : this . games ) {
2020-10-08 12:34:14 -05:00
if ( gameType . isInstance ( game ) ) {
2018-07-06 13:30:00 +00:00
return game ;
}
}
}
return null ;
}
2020-10-12 11:18:52 +02:00
public Game getGameOrCreate ( Class < ? extends Game > gameType ) {
Game game = this . getGame ( gameType ) ;
if ( game = = null ) {
try {
game = gameType . getDeclaredConstructor ( Room . class ) . newInstance ( this ) ;
this . addGame ( game ) ;
} catch ( Exception e ) {
LOGGER . error ( " Error getting game " + gameType . getName ( ) , e ) ;
}
}
return game ;
}
2019-06-03 16:49:17 -04:00
public ConcurrentSet < Game > getGames ( ) {
return this . games ;
}
2019-05-26 21:14:53 +03:00
public int getUserCount ( ) {
2019-05-04 02:25:43 +01:00
return this . currentHabbos . size ( ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public ConcurrentHashMap < Integer , Habbo > getCurrentHabbos ( ) {
2018-07-06 13:30:00 +00:00
return this . currentHabbos ;
}
2019-05-26 21:14:53 +03:00
public Collection < Habbo > getHabbos ( ) {
2018-07-06 13:30:00 +00:00
return this . currentHabbos . values ( ) ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectMap < Habbo > getHabboQueue ( ) {
2018-07-06 13:30:00 +00:00
return this . habboQueue ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectMap < String > getFurniOwnerNames ( ) {
2018-07-06 13:30:00 +00:00
return this . furniOwnerNames ;
}
2019-05-26 21:14:53 +03:00
public String getFurniOwnerName ( int userId ) {
2018-07-06 13:30:00 +00:00
return this . furniOwnerNames . get ( userId ) ;
}
2019-05-26 21:14:53 +03:00
public TIntIntMap getFurniOwnerCount ( ) {
2018-07-06 13:30:00 +00:00
return this . furniOwnerCount ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectMap < RoomMoodlightData > getMoodlightData ( ) {
2018-07-06 13:30:00 +00:00
return this . moodlightData ;
}
2019-05-26 21:14:53 +03:00
public int getLastTimerReset ( ) {
2018-07-06 13:30:00 +00:00
return this . lastTimerReset ;
}
2019-05-26 21:14:53 +03:00
public void setLastTimerReset ( int lastTimerReset ) {
2018-07-06 13:30:00 +00:00
this . lastTimerReset = lastTimerReset ;
}
2019-05-26 21:14:53 +03:00
public void addToQueue ( Habbo habbo ) {
synchronized ( this . habboQueue ) {
2018-07-06 13:30:00 +00:00
this . habboQueue . put ( habbo . getHabboInfo ( ) . getId ( ) , habbo ) ;
}
}
2019-05-26 21:14:53 +03:00
public boolean removeFromQueue ( Habbo habbo ) {
try {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new HideDoorbellComposer ( habbo . getHabboInfo ( ) . getUsername ( ) ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . habboQueue ) {
2018-07-06 13:30:00 +00:00
return this . habboQueue . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ! = null ;
}
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
return true ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectMap < Bot > getCurrentBots ( ) {
2018-07-06 13:30:00 +00:00
return this . currentBots ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectMap < Pet > getCurrentPets ( ) {
2018-07-06 13:30:00 +00:00
return this . currentPets ;
}
2019-05-26 21:14:53 +03:00
public THashSet < String > getWordFilterWords ( ) {
2018-07-06 13:30:00 +00:00
return this . wordFilterWords ;
}
2019-05-26 21:14:53 +03:00
public RoomSpecialTypes getRoomSpecialTypes ( ) {
2018-07-06 13:30:00 +00:00
return this . roomSpecialTypes ;
}
2019-05-26 21:14:53 +03:00
public boolean isPreLoaded ( ) {
2018-07-06 13:30:00 +00:00
return this . preLoaded ;
}
2019-05-26 21:14:53 +03:00
public boolean isLoaded ( ) {
2018-07-06 13:30:00 +00:00
return this . loaded ;
}
2019-05-26 21:14:53 +03:00
public void setNeedsUpdate ( boolean needsUpdate ) {
2018-07-06 13:30:00 +00:00
this . needsUpdate = needsUpdate ;
}
2019-05-26 21:14:53 +03:00
public TIntArrayList getRights ( ) {
2019-03-18 01:22:00 +00:00
return this . rights ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean isMuted ( ) {
2018-07-06 13:30:00 +00:00
return this . muted ;
}
2019-05-26 21:14:53 +03:00
public void setMuted ( boolean muted ) {
2018-07-06 13:30:00 +00:00
this . muted = muted ;
}
2019-05-26 21:14:53 +03:00
public TraxManager getTraxManager ( ) {
2018-07-06 13:30:00 +00:00
return this . traxManager ;
}
2019-05-26 21:14:53 +03:00
public void addHabboItem ( HabboItem item ) {
if ( item = = null )
2018-07-06 13:30:00 +00:00
return ;
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
try {
2019-03-18 01:22:00 +00:00
this . roomItems . put ( item . getId ( ) , item ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
2019-03-18 01:22:00 +00:00
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
synchronized ( this . furniOwnerCount ) {
2018-07-06 13:30:00 +00:00
this . furniOwnerCount . put ( item . getUserId ( ) , this . furniOwnerCount . get ( item . getUserId ( ) ) + 1 ) ;
}
2019-05-26 21:14:53 +03:00
synchronized ( this . furniOwnerNames ) {
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) ) {
2018-07-06 13:30:00 +00:00
HabboInfo habbo = HabboManager . getOfflineHabboInfo ( item . getUserId ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( habbo ! = null ) {
2018-07-06 13:30:00 +00:00
this . furniOwnerNames . put ( item . getUserId ( ) , habbo . getUsername ( ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Failed to find username for item (ID: {}, UserID: {}) " , item . getId ( ) , item . getUserId ( ) ) ;
2018-07-06 13:30:00 +00:00
}
}
}
//TODO: Move this list
2019-05-26 21:14:53 +03:00
synchronized ( this . roomSpecialTypes ) {
if ( item instanceof ICycleable ) {
this . roomSpecialTypes . addCycleTask ( ( ICycleable ) item ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
if ( item instanceof InteractionWiredTrigger ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addTrigger ( ( InteractionWiredTrigger ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredEffect ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addEffect ( ( InteractionWiredEffect ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredCondition ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addCondition ( ( InteractionWiredCondition ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredExtra ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addExtra ( ( InteractionWiredExtra ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionBattleBanzaiTeleporter ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addBanzaiTeleporter ( ( InteractionBattleBanzaiTeleporter ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionRoller ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addRoller ( ( InteractionRoller ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameScoreboard ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addGameScoreboard ( ( InteractionGameScoreboard ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameGate ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addGameGate ( ( InteractionGameGate ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameTimer ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addGameTimer ( ( InteractionGameTimer ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionFreezeExitTile ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addFreezeExitTile ( ( InteractionFreezeExitTile ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionNest ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addNest ( ( InteractionNest ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetDrink ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addPetDrink ( ( InteractionPetDrink ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetFood ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addPetFood ( ( InteractionPetFood ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMoodLight ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPyramid ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMusicDisc ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionBattleBanzaiSphere ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTalkingFurniture ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWater ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWaterItem ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMuteArea ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTagPole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTagField ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionJukeBox ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetBreedingNest ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionBlackHole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredHighscore ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionStickyPole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof WiredBlob ) {
2018-09-28 19:25:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTent ) {
2018-09-28 19:25:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionSnowboardSlope ) {
2018-12-22 10:39:00 +00:00
this . roomSpecialTypes . addUndefined ( item ) ;
}
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public HabboItem getHabboItem ( int id ) {
2020-02-08 18:25:44 +02:00
if ( this . roomItems = = null | | this . roomSpecialTypes = = null )
return null ; // room not loaded completely
2018-07-06 13:30:00 +00:00
HabboItem item ;
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
2018-07-06 13:30:00 +00:00
item = this . roomItems . get ( id ) ;
}
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getBanzaiTeleporter ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getTrigger ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getEffect ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getCondition ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getGameGate ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getGameScorebord ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getGameTimer ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getFreezeExitTiles ( ) . get ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getRoller ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getNest ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getPetDrink ( id ) ;
2019-05-26 21:14:53 +03:00
if ( item = = null )
2018-07-06 13:30:00 +00:00
item = this . roomSpecialTypes . getPetFood ( id ) ;
return item ;
}
2019-05-26 21:14:53 +03:00
void removeHabboItem ( int id ) {
2018-07-06 13:30:00 +00:00
this . removeHabboItem ( this . getHabboItem ( id ) ) ;
}
2018-07-08 21:32:00 +00:00
2019-05-26 21:14:53 +03:00
public void removeHabboItem ( HabboItem item ) {
if ( item ! = null ) {
2018-07-06 13:30:00 +00:00
HabboItem i ;
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
2018-07-06 13:30:00 +00:00
i = this . roomItems . remove ( item . getId ( ) ) ;
}
2019-05-26 21:14:53 +03:00
if ( i ! = null ) {
synchronized ( this . furniOwnerCount ) {
synchronized ( this . furniOwnerNames ) {
2018-07-06 13:30:00 +00:00
int count = this . furniOwnerCount . get ( i . getUserId ( ) ) ;
if ( count > 1 )
this . furniOwnerCount . put ( i . getUserId ( ) , count - 1 ) ;
2019-05-26 21:14:53 +03:00
else {
2018-07-06 13:30:00 +00:00
this . furniOwnerCount . remove ( i . getUserId ( ) ) ;
this . furniOwnerNames . remove ( i . getUserId ( ) ) ;
}
}
}
2019-05-26 21:14:53 +03:00
if ( item instanceof ICycleable ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeCycleTask ( ( ICycleable ) item ) ;
}
2019-05-26 21:14:53 +03:00
if ( item instanceof InteractionBattleBanzaiTeleporter ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeBanzaiTeleporter ( ( InteractionBattleBanzaiTeleporter ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredTrigger ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeTrigger ( ( InteractionWiredTrigger ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredEffect ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeEffect ( ( InteractionWiredEffect ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredCondition ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeCondition ( ( InteractionWiredCondition ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredExtra ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeExtra ( ( InteractionWiredExtra ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionRoller ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeRoller ( ( InteractionRoller ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameScoreboard ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeScoreboard ( ( InteractionGameScoreboard ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameGate ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeGameGate ( ( InteractionGameGate ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionGameTimer ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeGameTimer ( ( InteractionGameTimer ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionFreezeExitTile ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeFreezeExitTile ( ( InteractionFreezeExitTile ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionNest ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeNest ( ( InteractionNest ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetDrink ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removePetDrink ( ( InteractionPetDrink ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetFood ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removePetFood ( ( InteractionPetFood ) item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMoodLight ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPyramid ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMusicDisc ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionBattleBanzaiSphere ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTalkingFurniture ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWaterItem ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWater ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionMuteArea ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTagPole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTagField ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionJukeBox ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionPetBreedingNest ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionBlackHole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionWiredHighscore ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionStickyPole ) {
2018-07-06 13:30:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof WiredBlob ) {
2018-09-28 19:25:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionTent ) {
2018-09-28 19:25:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
2019-05-26 21:14:53 +03:00
} else if ( item instanceof InteractionSnowboardSlope ) {
2018-12-22 10:39:00 +00:00
this . roomSpecialTypes . removeUndefined ( item ) ;
}
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getFloorItems ( ) {
2018-09-28 19:25:00 +00:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
if ( iterator . value ( ) . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR )
items . add ( iterator . value ( ) ) ;
}
2018-07-08 21:32:00 +00:00
2019-05-04 02:25:43 +01:00
return items ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getWallItems ( ) {
2018-09-28 19:25:00 +00:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
if ( iterator . value ( ) . getBaseItem ( ) . getType ( ) = = FurnitureType . WALL )
items . add ( iterator . value ( ) ) ;
}
return items ;
}
2020-04-23 22:17:04 +01:00
public THashSet < HabboItem > getPostItNotes ( ) {
THashSet < HabboItem > items = new THashSet < > ( ) ;
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
iterator . advance ( ) ;
} catch ( Exception e ) {
break ;
}
if ( iterator . value ( ) . getBaseItem ( ) . getInteractionType ( ) . getType ( ) = = InteractionPostIt . class )
items . add ( iterator . value ( ) ) ;
}
return items ;
}
2019-05-26 21:14:53 +03:00
public void addHabbo ( Habbo habbo ) {
synchronized ( this . roomUnitLock ) {
2019-05-04 02:25:43 +01:00
habbo . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentHabbos . put ( habbo . getHabboInfo ( ) . getId ( ) , habbo ) ;
this . unitCounter + + ;
this . updateDatabaseUserCount ( ) ;
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void kickHabbo ( Habbo habbo , boolean alert ) {
if ( alert ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new GenericErrorMessagesComposer ( GenericErrorMessagesComposer . KICKED_OUT_OF_THE_ROOM ) ) ;
}
habbo . getRoomUnit ( ) . isKicked = true ;
habbo . getRoomUnit ( ) . setGoalLocation ( this . layout . getDoorTile ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( habbo . getRoomUnit ( ) . getPath ( ) = = null | | habbo . getRoomUnit ( ) . getPath ( ) . size ( ) < = 1 | | this . isPublicRoom ( ) ) {
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . setCanWalk ( true ) ;
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
}
2019-05-12 08:59:01 +01:00
public void removeHabbo ( Habbo habbo ) {
removeHabbo ( habbo , false ) ;
}
2019-05-26 21:14:53 +03:00
public void removeHabbo ( Habbo habbo , boolean sendRemovePacket ) {
if ( habbo . getRoomUnit ( ) ! = null & & habbo . getRoomUnit ( ) . getCurrentLocation ( ) ! = null ) {
2019-05-12 08:59:01 +01:00
habbo . getRoomUnit ( ) . getCurrentLocation ( ) . removeUnit ( habbo . getRoomUnit ( ) ) ;
}
2020-08-26 11:24:18 -03:00
if ( sendRemovePacket & & habbo . getRoomUnit ( ) ! = null & & ! habbo . getRoomUnit ( ) . isTeleporting ) {
2019-05-12 08:59:01 +01:00
this . sendComposer ( new RoomUserRemoveComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
}
2020-02-27 22:35:03 +02:00
if ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ! = null ) {
HabboItem item = this . getTopItemAt ( habbo . getRoomUnit ( ) . getX ( ) , habbo . getRoomUnit ( ) . getY ( ) ) ;
2018-07-06 13:30:00 +00:00
2020-02-27 22:35:03 +02:00
if ( item ! = null ) {
try {
item . onWalkOff ( habbo . getRoomUnit ( ) , this , new Object [ ] { } ) ;
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2020-02-27 22:35:03 +02:00
}
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
synchronized ( this . roomUnitLock ) {
2018-07-06 13:30:00 +00:00
this . currentHabbos . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
2019-05-26 21:14:53 +03:00
if ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ! = null ) {
if ( this . getGame ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ) ! = null ) {
2018-07-06 13:30:00 +00:00
this . getGame ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ) . removeHabbo ( habbo ) ;
}
}
RoomTrade trade = this . getActiveTradeForHabbo ( habbo ) ;
2019-05-26 21:14:53 +03:00
if ( trade ! = null ) {
2018-07-06 13:30:00 +00:00
trade . stopTrade ( habbo ) ;
}
2019-05-26 21:14:53 +03:00
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . ownerId ) {
2019-05-06 05:23:51 +01:00
this . pickupPetsForHabbo ( habbo ) ;
}
2018-07-06 13:30:00 +00:00
this . updateDatabaseUserCount ( ) ;
}
2019-05-26 21:14:53 +03:00
public void addBot ( Bot bot ) {
synchronized ( this . roomUnitLock ) {
2018-07-06 13:30:00 +00:00
bot . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentBots . put ( bot . getId ( ) , bot ) ;
this . unitCounter + + ;
}
}
2019-05-26 21:14:53 +03:00
public void addPet ( Pet pet ) {
synchronized ( this . roomUnitLock ) {
2018-07-06 13:30:00 +00:00
pet . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentPets . put ( pet . getId ( ) , pet ) ;
this . unitCounter + + ;
Habbo habbo = this . getHabbo ( pet . getUserId ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( habbo ! = null ) {
2018-07-06 13:30:00 +00:00
this . furniOwnerNames . put ( pet . getUserId ( ) , this . getHabbo ( pet . getUserId ( ) ) . getHabboInfo ( ) . getUsername ( ) ) ;
}
}
}
2019-05-26 21:14:53 +03:00
public Bot getBot ( int botId ) {
2018-07-06 13:30:00 +00:00
return this . currentBots . get ( botId ) ;
}
2019-05-26 21:14:53 +03:00
public Bot getBot ( RoomUnit roomUnit ) {
synchronized ( this . currentBots ) {
2018-12-22 10:39:00 +00:00
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-12-22 10:39:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-12-22 10:39:00 +00:00
break ;
}
if ( iterator . value ( ) . getRoomUnit ( ) = = roomUnit )
return iterator . value ( ) ;
}
}
return null ;
}
2019-05-26 21:14:53 +03:00
public Bot getBotByRoomUnitId ( int id ) {
synchronized ( this . currentBots ) {
2018-12-22 10:39:00 +00:00
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-12-22 10:39:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-12-22 10:39:00 +00:00
break ;
}
if ( iterator . value ( ) . getRoomUnit ( ) . getId ( ) = = id )
return iterator . value ( ) ;
}
}
return null ;
}
2019-05-26 21:14:53 +03:00
public List < Bot > getBots ( String name ) {
2018-09-28 19:25:00 +00:00
List < Bot > bots = new ArrayList < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
synchronized ( this . currentBots ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
break ;
}
if ( iterator . value ( ) . getName ( ) . equalsIgnoreCase ( name ) )
bots . add ( iterator . value ( ) ) ;
}
}
return bots ;
}
2019-05-26 21:14:53 +03:00
public boolean hasBotsAt ( final int x , final int y ) {
2018-07-06 13:30:00 +00:00
final boolean [ ] result = { false } ;
2019-05-26 21:14:53 +03:00
synchronized ( this . currentBots ) {
this . currentBots . forEachValue ( new TObjectProcedure < Bot > ( ) {
2018-07-06 13:30:00 +00:00
@Override
2019-05-26 21:14:53 +03:00
public boolean execute ( Bot object ) {
if ( object . getRoomUnit ( ) . getX ( ) = = x & & object . getRoomUnit ( ) . getY ( ) = = y ) {
2018-07-06 13:30:00 +00:00
result [ 0 ] = true ;
return false ;
}
return true ;
}
} ) ;
}
return result [ 0 ] ;
}
2019-05-26 21:14:53 +03:00
public Pet getPet ( int petId ) {
2018-07-06 13:30:00 +00:00
return this . currentPets . get ( petId ) ;
}
2019-05-26 21:14:53 +03:00
public Pet getPet ( RoomUnit roomUnit ) {
2018-09-12 16:45:00 +00:00
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
petIterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
break ;
}
2019-05-26 21:14:53 +03:00
if ( petIterator . value ( ) . getRoomUnit ( ) = = roomUnit )
2018-07-06 13:30:00 +00:00
return petIterator . value ( ) ;
}
return null ;
}
2019-05-26 21:14:53 +03:00
public boolean removeBot ( Bot bot ) {
synchronized ( this . currentBots ) {
if ( this . currentBots . containsKey ( bot . getId ( ) ) ) {
if ( bot . getRoomUnit ( ) ! = null & & bot . getRoomUnit ( ) . getCurrentLocation ( ) ! = null ) {
2019-05-12 08:59:01 +01:00
bot . getRoomUnit ( ) . getCurrentLocation ( ) . removeUnit ( bot . getRoomUnit ( ) ) ;
}
2018-07-06 13:30:00 +00:00
this . currentBots . remove ( bot . getId ( ) ) ;
bot . getRoomUnit ( ) . setInRoom ( false ) ;
bot . setRoom ( null ) ;
this . sendComposer ( new RoomUserRemoveComposer ( bot . getRoomUnit ( ) ) . compose ( ) ) ;
bot . setRoomUnit ( null ) ;
return true ;
}
}
return false ;
}
2019-05-26 21:14:53 +03:00
public void placePet ( Pet pet , short x , short y , double z , int rot ) {
synchronized ( this . currentPets ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( x , y ) ;
2019-05-26 21:14:53 +03:00
if ( tile = = null ) {
2018-07-06 13:30:00 +00:00
tile = this . layout . getDoorTile ( ) ;
}
pet . setRoomUnit ( new RoomUnit ( ) ) ;
pet . setRoom ( this ) ;
2018-10-06 22:28:00 +00:00
pet . getRoomUnit ( ) . setGoalLocation ( tile ) ;
2018-07-06 13:30:00 +00:00
pet . getRoomUnit ( ) . setLocation ( tile ) ;
pet . getRoomUnit ( ) . setRoomUnitType ( RoomUnitType . PET ) ;
pet . getRoomUnit ( ) . setCanWalk ( true ) ;
pet . getRoomUnit ( ) . setPathFinderRoom ( this ) ;
2018-10-06 22:28:00 +00:00
pet . getRoomUnit ( ) . setPreviousLocationZ ( z ) ;
pet . getRoomUnit ( ) . setZ ( z ) ;
2019-05-26 21:14:53 +03:00
if ( pet . getRoomUnit ( ) . getCurrentLocation ( ) = = null ) {
2018-07-06 13:30:00 +00:00
pet . getRoomUnit ( ) . setLocation ( this . getLayout ( ) . getDoorTile ( ) ) ;
pet . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( this . getLayout ( ) . getDoorDirection ( ) ) ) ;
}
pet . needsUpdate = true ;
this . furniOwnerNames . put ( pet . getUserId ( ) , this . getHabbo ( pet . getUserId ( ) ) . getHabboInfo ( ) . getUsername ( ) ) ;
this . addPet ( pet ) ;
this . sendComposer ( new RoomPetComposer ( pet ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public Pet removePet ( int petId ) {
2018-07-06 13:30:00 +00:00
return this . currentPets . remove ( petId ) ;
}
2019-05-26 21:14:53 +03:00
public boolean hasHabbosAt ( int x , int y ) {
for ( Habbo habbo : this . getHabbos ( ) ) {
2018-07-06 13:30:00 +00:00
if ( habbo . getRoomUnit ( ) . getX ( ) = = x & & habbo . getRoomUnit ( ) . getY ( ) = = y )
return true ;
}
return false ;
}
2019-05-26 21:14:53 +03:00
public boolean hasPetsAt ( int x , int y ) {
synchronized ( this . currentPets ) {
2018-09-12 16:45:00 +00:00
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
petIterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
break ;
}
if ( petIterator . value ( ) . getRoomUnit ( ) . getX ( ) = = x & & petIterator . value ( ) . getRoomUnit ( ) . getY ( ) = = y )
return true ;
}
}
return false ;
}
2019-05-26 21:14:53 +03:00
public THashSet < Bot > getBotsAt ( RoomTile tile ) {
2018-12-22 10:39:00 +00:00
THashSet < Bot > bots = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
synchronized ( this . currentBots ) {
2018-12-22 10:39:00 +00:00
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-12-22 10:39:00 +00:00
botIterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
if ( botIterator . value ( ) . getRoomUnit ( ) . getCurrentLocation ( ) . equals ( tile ) ) {
2018-12-22 10:39:00 +00:00
bots . add ( botIterator . value ( ) ) ;
}
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-12-22 10:39:00 +00:00
break ;
}
}
}
return bots ;
}
2019-05-26 21:14:53 +03:00
public THashSet < Habbo > getHabbosAt ( short x , short y ) {
2019-03-18 01:22:00 +00:00
return this . getHabbosAt ( this . layout . getTile ( x , y ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public THashSet < Habbo > getHabbosAt ( RoomTile tile ) {
2018-09-28 19:25:00 +00:00
THashSet < Habbo > habbos = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : this . getHabbos ( ) ) {
2018-07-06 13:30:00 +00:00
if ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) . equals ( tile ) )
habbos . add ( habbo ) ;
}
return habbos ;
}
2020-10-08 12:34:14 -05:00
public THashSet < RoomUnit > getHabbosAndBotsAt ( short x , short y ) {
return this . getHabbosAndBotsAt ( this . layout . getTile ( x , y ) ) ;
}
public THashSet < RoomUnit > getHabbosAndBotsAt ( RoomTile tile ) {
THashSet < RoomUnit > list = new THashSet < > ( ) ;
for ( Bot bot : this . getBotsAt ( tile ) ) {
list . add ( bot . getRoomUnit ( ) ) ;
}
for ( Habbo habbo : this . getHabbosAt ( tile ) )
{
list . add ( habbo . getRoomUnit ( ) ) ;
}
return list ;
}
2019-05-26 21:14:53 +03:00
public THashSet < Habbo > getHabbosOnItem ( HabboItem item ) {
2018-09-28 19:25:00 +00:00
THashSet < Habbo > habbos = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( short x = item . getX ( ) ; x < item . getX ( ) + item . getBaseItem ( ) . getLength ( ) ; x + + ) {
for ( short y = item . getY ( ) ; y < item . getY ( ) + item . getBaseItem ( ) . getWidth ( ) ; y + + ) {
2019-03-18 01:22:00 +00:00
habbos . addAll ( this . getHabbosAt ( x , y ) ) ;
2018-07-06 13:30:00 +00:00
}
}
return habbos ;
}
2019-05-26 21:14:53 +03:00
public THashSet < Bot > getBotsOnItem ( HabboItem item ) {
2018-12-22 10:39:00 +00:00
THashSet < Bot > bots = new THashSet < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( short x = item . getX ( ) ; x < item . getX ( ) + item . getBaseItem ( ) . getLength ( ) ; x + + ) {
for ( short y = item . getY ( ) ; y < item . getY ( ) + item . getBaseItem ( ) . getWidth ( ) ; y + + ) {
2019-03-18 01:22:00 +00:00
bots . addAll ( this . getBotsAt ( this . getLayout ( ) . getTile ( x , y ) ) ) ;
2018-12-22 10:39:00 +00:00
}
}
return bots ;
}
2019-05-26 21:14:53 +03:00
public void teleportHabboToItem ( Habbo habbo , HabboItem item ) {
2019-05-12 08:59:01 +01:00
this . teleportRoomUnitToLocation ( habbo . getRoomUnit ( ) , item . getX ( ) , item . getY ( ) , item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void teleportHabboToLocation ( Habbo habbo , short x , short y ) {
2019-03-18 01:22:00 +00:00
this . teleportRoomUnitToLocation ( habbo . getRoomUnit ( ) , x , y , 0 . 0 ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void teleportRoomUnitToItem ( RoomUnit roomUnit , HabboItem item ) {
2019-05-12 08:59:01 +01:00
this . teleportRoomUnitToLocation ( roomUnit , item . getX ( ) , item . getY ( ) , item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2019-03-18 01:22:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void teleportRoomUnitToLocation ( RoomUnit roomUnit , short x , short y ) {
2019-03-18 01:22:00 +00:00
this . teleportRoomUnitToLocation ( roomUnit , x , y , 0 . 0 ) ;
}
2019-05-26 21:14:53 +03:00
2020-10-15 04:39:30 +02:00
public void teleportRoomUnitToLocation ( RoomUnit roomUnit , short x , short y , double z ) {
2019-05-26 21:14:53 +03:00
if ( this . loaded ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( x , y ) ;
2019-03-18 01:22:00 +00:00
2019-05-26 21:14:53 +03:00
if ( z < tile . z ) {
2019-03-18 01:22:00 +00:00
z = tile . z ;
}
roomUnit . setLocation ( tile ) ;
roomUnit . setGoalLocation ( tile ) ;
roomUnit . setZ ( z ) ;
roomUnit . setPreviousLocationZ ( z ) ;
this . updateRoomUnit ( roomUnit ) ;
2019-04-21 23:42:00 +00:00
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void muteHabbo ( Habbo habbo , int minutes ) {
synchronized ( this . mutedHabbos ) {
2018-07-06 13:30:00 +00:00
this . mutedHabbos . put ( habbo . getHabboInfo ( ) . getId ( ) , Emulator . getIntUnixTimestamp ( ) + ( minutes * 60 ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public boolean isMuted ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
if ( this . isOwner ( habbo ) | | this . hasRights ( habbo ) )
return false ;
2019-05-26 21:14:53 +03:00
if ( this . mutedHabbos . containsKey ( habbo . getHabboInfo ( ) . getId ( ) ) ) {
2018-07-06 13:30:00 +00:00
boolean time = this . mutedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) > Emulator . getIntUnixTimestamp ( ) ;
2019-05-26 21:14:53 +03:00
if ( ! time ) {
2018-07-06 13:30:00 +00:00
this . mutedHabbos . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
return time ;
}
return false ;
}
2019-05-26 21:14:53 +03:00
public void habboEntered ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . animateWalk = false ;
2019-05-26 21:14:53 +03:00
synchronized ( this . currentBots ) {
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . getOwnerId ( ) )
2018-07-06 13:30:00 +00:00
return ;
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
botIterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
if ( botIterator . value ( ) instanceof VisitorBot ) {
( ( VisitorBot ) botIterator . value ( ) ) . onUserEnter ( habbo ) ;
2018-07-06 13:30:00 +00:00
break ;
}
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
}
}
2018-12-22 10:39:00 +00:00
HabboItem doorTileTopItem = this . getTopItemAt ( habbo . getRoomUnit ( ) . getX ( ) , habbo . getRoomUnit ( ) . getY ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( doorTileTopItem ! = null & & ! ( doorTileTopItem instanceof InteractionTeleportTile ) ) {
try {
2018-12-22 10:39:00 +00:00
doorTileTopItem . onWalkOn ( habbo . getRoomUnit ( ) , this , new Object [ ] { } ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-12-22 10:39:00 +00:00
}
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void floodMuteHabbo ( Habbo habbo , int timeOut ) {
2018-07-06 13:30:00 +00:00
habbo . getHabboStats ( ) . mutedCount + + ;
2019-05-26 21:14:53 +03:00
timeOut + = ( timeOut * ( int ) Math . ceil ( Math . pow ( habbo . getHabboStats ( ) . mutedCount , 2 ) ) ) ;
2020-06-12 22:10:05 +02:00
habbo . getHabboStats ( ) . chatCounter . set ( 0 ) ;
2020-01-22 20:56:56 +01:00
habbo . mute ( timeOut , true ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void talk ( Habbo habbo , RoomChatMessage roomChatMessage , RoomChatType chatType ) {
2020-07-31 16:03:04 -04:00
this . talk ( habbo , roomChatMessage , chatType , false ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void talk ( final Habbo habbo , final RoomChatMessage roomChatMessage , RoomChatType chatType , boolean ignoreWired ) {
2018-07-06 13:30:00 +00:00
if ( ! habbo . getHabboStats ( ) . allowTalk ( ) )
return ;
2019-05-16 19:46:37 +03:00
if ( habbo . getRoomUnit ( ) . isInvisible ( ) & & Emulator . getConfig ( ) . getBoolean ( " invisible.prevent.chat " , false ) ) {
if ( ! CommandHandler . handleCommand ( habbo . getClient ( ) , roomChatMessage . getUnfilteredMessage ( ) ) ) {
habbo . whisper ( Emulator . getTexts ( ) . getValue ( " invisible.prevent.chat.error " ) ) ;
}
return ;
}
2018-07-06 13:30:00 +00:00
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) ! = this )
return ;
long millis = System . currentTimeMillis ( ) ;
2019-05-26 21:14:53 +03:00
if ( HABBO_CHAT_DELAY ) {
if ( millis - habbo . getHabboStats ( ) . lastChat < 750 ) {
2018-07-06 13:30:00 +00:00
return ;
}
}
habbo . getHabboStats ( ) . lastChat = millis ;
2020-12-20 14:07:31 +00:00
if ( roomChatMessage ! = null & & Emulator . getConfig ( ) . getBoolean ( " easter_eggs.enabled " ) & & roomChatMessage . getMessage ( ) . equalsIgnoreCase ( " i am a pirate " ) ) {
2020-06-12 22:10:05 +02:00
habbo . getHabboStats ( ) . chatCounter . addAndGet ( 1 ) ;
2018-07-06 13:30:00 +00:00
Emulator . getThreading ( ) . run ( new YouAreAPirate ( habbo , this ) ) ;
return ;
}
UserIdleEvent event = new UserIdleEvent ( habbo , UserIdleEvent . IdleReason . TALKED , false ) ;
Emulator . getPluginManager ( ) . fireEvent ( event ) ;
2019-05-26 21:14:53 +03:00
if ( ! event . isCancelled ( ) ) {
if ( ! event . idle ) {
2018-07-06 13:30:00 +00:00
this . unIdle ( habbo ) ;
}
}
this . sendComposer ( new RoomUserTypingComposer ( habbo . getRoomUnit ( ) , false ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( roomChatMessage = = null | | roomChatMessage . getMessage ( ) = = null | | roomChatMessage . getMessage ( ) . equals ( " " ) )
2018-07-06 13:30:00 +00:00
return ;
2020-10-13 03:42:30 +02:00
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 ;
}
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
if ( ! this . wordFilterWords . isEmpty ( ) ) {
2020-06-05 04:12:49 -04:00
if ( ! habbo . hasPermission ( Permission . ACC_CHAT_NO_FILTER ) ) {
2019-05-26 21:14:53 +03:00
for ( String string : this . wordFilterWords ) {
2020-06-07 15:54:08 +03:00
roomChatMessage . setMessage ( roomChatMessage . getMessage ( ) . replaceAll ( " (?i) " + Pattern . quote ( string ) , " bobba " ) ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2020-06-05 04:12:49 -04:00
if ( ! habbo . hasPermission ( Permission . ACC_NOMUTE ) ) {
2019-05-26 21:14:53 +03:00
if ( this . isMuted ( ) & & ! this . hasRights ( habbo ) ) {
2018-07-06 13:30:00 +00:00
return ;
}
2019-05-26 21:14:53 +03:00
if ( this . isMuted ( habbo ) ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new MutedWhisperComposer ( this . mutedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) - Emulator . getIntUnixTimestamp ( ) ) ) ;
return ;
}
}
2019-05-26 21:14:53 +03:00
if ( chatType ! = RoomChatType . WHISPER ) {
if ( CommandHandler . handleCommand ( habbo . getClient ( ) , roomChatMessage . getUnfilteredMessage ( ) ) ) {
2018-07-06 13:30:00 +00:00
WiredHandler . handle ( WiredTriggerType . SAY_COMMAND , habbo . getRoomUnit ( ) , habbo . getHabboInfo ( ) . getCurrentRoom ( ) , new Object [ ] { roomChatMessage . getMessage ( ) } ) ;
roomChatMessage . isCommand = true ;
return ;
}
2019-05-26 21:14:53 +03:00
if ( ! ignoreWired ) {
if ( WiredHandler . handle ( WiredTriggerType . SAY_SOMETHING , habbo . getRoomUnit ( ) , habbo . getHabboInfo ( ) . getCurrentRoom ( ) , new Object [ ] { roomChatMessage . getMessage ( ) } ) ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new RoomUserWhisperComposer ( new RoomChatMessage ( roomChatMessage . getMessage ( ) , habbo , habbo , roomChatMessage . getBubble ( ) ) ) ) ;
return ;
}
}
}
2020-06-12 22:10:05 +02:00
if ( ! habbo . hasPermission ( Permission . ACC_CHAT_NO_FLOOD ) ) {
final int chatCounter = habbo . getHabboStats ( ) . chatCounter . addAndGet ( 1 ) ;
if ( chatCounter > 3 ) {
final boolean floodRights = Emulator . getConfig ( ) . getBoolean ( " flood.with.rights " ) ;
final boolean hasRights = this . hasRights ( habbo ) ;
if ( floodRights | | ! hasRights ) {
if ( this . chatProtection = = 0 ) {
this . floodMuteHabbo ( habbo , muteTime ) ;
return ;
} else if ( this . chatProtection = = 1 & & chatCounter > 4 ) {
this . floodMuteHabbo ( habbo , muteTime ) ;
return ;
} else if ( this . chatProtection = = 2 & & chatCounter > 5 ) {
this . floodMuteHabbo ( habbo , muteTime ) ;
return ;
}
}
}
}
2019-07-24 19:34:31 +03:00
2020-06-08 17:46:19 +02:00
ServerMessage prefixMessage = null ;
if ( Emulator . getPluginManager ( ) . isRegistered ( UsernameTalkEvent . class , true ) ) {
2020-10-08 12:34:14 -05:00
UsernameTalkEvent usernameTalkEvent = Emulator . getPluginManager ( ) . fireEvent ( new UsernameTalkEvent ( habbo , roomChatMessage , chatType ) ) ;
2020-06-08 17:46:19 +02:00
if ( usernameTalkEvent . hasCustomComposer ( ) ) {
prefixMessage = usernameTalkEvent . getCustomComposer ( ) ;
}
}
2020-06-21 02:28:34 +02:00
if ( prefixMessage = = null ) {
2020-06-08 17:46:19 +02:00
prefixMessage = roomChatMessage . getHabbo ( ) . getHabboInfo ( ) . getRank ( ) . hasPrefix ( ) ? new RoomUserNameChangedComposer ( habbo , true ) . compose ( ) : null ;
}
2018-07-06 13:30:00 +00:00
ServerMessage clearPrefixMessage = prefixMessage ! = null ? new RoomUserNameChangedComposer ( habbo ) . compose ( ) : null ;
2020-11-29 00:07:20 -05:00
Rectangle tentRectangle = this . roomSpecialTypes . tentAt ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) ;
2018-09-28 19:25:00 +00:00
2019-07-15 10:42:00 +03:00
String trimmedMessage = roomChatMessage . getMessage ( ) . replaceAll ( " \\ s+$ " , " " ) ;
if ( trimmedMessage . isEmpty ( ) ) trimmedMessage = " " ;
roomChatMessage . setMessage ( trimmedMessage ) ;
2019-06-23 23:20:25 +03:00
2020-05-13 20:55:07 +02:00
if ( chatType = = RoomChatType . WHISPER ) {
if ( roomChatMessage . getTargetHabbo ( ) = = null ) {
return ;
}
2020-05-10 00:11:56 +02:00
2020-05-13 20:55:07 +02:00
RoomChatMessage staffChatMessage = new RoomChatMessage ( roomChatMessage ) ;
staffChatMessage . setMessage ( " To " + staffChatMessage . getTargetHabbo ( ) . getHabboInfo ( ) . getUsername ( ) + " : " + staffChatMessage . getMessage ( ) ) ;
2020-05-10 00:11:56 +02:00
2020-05-13 20:55:07 +02:00
final ServerMessage message = new RoomUserWhisperComposer ( roomChatMessage ) . compose ( ) ;
final ServerMessage staffMessage = new RoomUserWhisperComposer ( staffChatMessage ) . compose ( ) ;
2018-07-06 13:30:00 +00:00
2020-05-13 20:55:07 +02:00
for ( Habbo h : this . getHabbos ( ) ) {
if ( h = = roomChatMessage . getTargetHabbo ( ) | | h = = habbo ) {
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) ) {
if ( prefixMessage ! = null ) {
h . getClient ( ) . sendResponse ( prefixMessage ) ;
2020-05-10 00:11:56 +02:00
}
2020-05-13 20:55:07 +02:00
h . getClient ( ) . sendResponse ( message ) ;
2020-05-10 00:11:56 +02:00
2020-05-13 20:55:07 +02:00
if ( clearPrefixMessage ! = null ) {
h . getClient ( ) . sendResponse ( clearPrefixMessage ) ;
2020-05-10 00:11:56 +02:00
}
2020-05-09 23:05:51 +02:00
}
2018-07-06 13:30:00 +00:00
2020-05-13 20:55:07 +02:00
continue ;
}
2020-06-05 04:12:49 -04:00
if ( h . hasPermission ( Permission . ACC_SEE_WHISPERS ) ) {
2020-05-13 20:55:07 +02:00
h . getClient ( ) . sendResponse ( staffMessage ) ;
}
}
} else if ( chatType = = RoomChatType . TALK ) {
ServerMessage message = new RoomUserTalkComposer ( roomChatMessage ) . compose ( ) ;
2020-06-05 04:12:49 -04:00
boolean noChatLimit = habbo . hasPermission ( Permission . ACC_CHAT_NO_LIMIT ) ;
2020-05-09 23:05:51 +02:00
2020-05-13 20:55:07 +02:00
for ( Habbo h : this . getHabbos ( ) ) {
if ( ( h . getRoomUnit ( ) . getCurrentLocation ( ) . distance ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) < = this . chatDistance | |
h . equals ( habbo ) | |
this . hasRights ( h ) | |
2020-11-29 00:07:20 -05:00
noChatLimit ) & & ( tentRectangle = = null | | RoomLayout . tileInSquare ( tentRectangle , h . getRoomUnit ( ) . getCurrentLocation ( ) ) ) ) {
2020-05-13 20:55:07 +02:00
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) ) {
if ( prefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) {
h . getClient ( ) . sendResponse ( prefixMessage ) ;
}
h . getClient ( ) . sendResponse ( message ) ;
if ( clearPrefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) {
h . getClient ( ) . sendResponse ( clearPrefixMessage ) ;
2018-07-06 13:30:00 +00:00
}
}
2020-11-29 00:07:20 -05:00
continue ;
2018-07-06 13:30:00 +00:00
}
2020-11-29 00:07:20 -05:00
// Staff should be able to see the tent chat anyhow
showTentChatMessageOutsideTentIfPermitted ( h , roomChatMessage , tentRectangle ) ;
2018-07-06 13:30:00 +00:00
}
2020-05-13 20:55:07 +02:00
} else if ( chatType = = RoomChatType . SHOUT ) {
ServerMessage message = new RoomUserShoutComposer ( roomChatMessage ) . compose ( ) ;
2020-05-09 23:05:51 +02:00
2020-05-13 20:55:07 +02:00
for ( Habbo h : this . getHabbos ( ) ) {
2020-11-29 00:07:20 -05:00
// Show the message
// If the receiving Habbo has not ignored the sending Habbo
// AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) & & ( tentRectangle = = null | | RoomLayout . tileInSquare ( tentRectangle , h . getRoomUnit ( ) . getCurrentLocation ( ) ) ) ) {
2020-05-13 20:55:07 +02:00
if ( prefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) {
h . getClient ( ) . sendResponse ( prefixMessage ) ;
}
h . getClient ( ) . sendResponse ( message ) ;
if ( clearPrefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) {
h . getClient ( ) . sendResponse ( clearPrefixMessage ) ;
}
2020-11-29 00:07:20 -05:00
continue ;
2020-05-13 20:55:07 +02:00
}
2020-11-29 00:07:20 -05:00
// Staff should be able to see the tent chat anyhow, even when not in the same tent
showTentChatMessageOutsideTentIfPermitted ( h , roomChatMessage , tentRectangle ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
if ( chatType = = RoomChatType . TALK | | chatType = = RoomChatType . SHOUT ) {
synchronized ( this . currentBots ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
botIterator . advance ( ) ;
Bot bot = botIterator . value ( ) ;
bot . onUserSay ( roomChatMessage ) ;
2019-05-26 21:14:53 +03:00
} catch ( NoSuchElementException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
break ;
}
}
}
2019-05-26 21:14:53 +03:00
if ( roomChatMessage . getBubble ( ) . triggersTalkingFurniture ( ) ) {
2018-12-22 10:39:00 +00:00
THashSet < HabboItem > items = this . roomSpecialTypes . getItemsOfType ( InteractionTalkingFurniture . class ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( HabboItem item : items ) {
if ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) . distance ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) < = Emulator . getConfig ( ) . getInt ( " furniture.talking.range " ) ) {
2018-12-22 10:39:00 +00:00
int count = Emulator . getConfig ( ) . getInt ( item . getBaseItem ( ) . getName ( ) + " .message.count " , 0 ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( count > 0 ) {
2018-12-22 10:39:00 +00:00
int randomValue = Emulator . getRandom ( ) . nextInt ( count + 1 ) ;
2018-07-06 13:30:00 +00:00
2018-12-22 10:39:00 +00:00
RoomChatMessage itemMessage = new RoomChatMessage ( Emulator . getTexts ( ) . getValue ( item . getBaseItem ( ) . getName ( ) + " .message. " + randomValue , item . getBaseItem ( ) . getName ( ) + " .message. " + randomValue + " not found! " ) , habbo , RoomChatMessageBubbles . getBubble ( Emulator . getConfig ( ) . getInt ( item . getBaseItem ( ) . getName ( ) + " .message.bubble " , RoomChatMessageBubbles . PARROT . getType ( ) ) ) ) ;
2018-07-06 13:30:00 +00:00
2020-09-17 07:35:00 +02:00
this . sendComposer ( new RoomUserTalkComposer ( itemMessage ) . compose ( ) ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
try {
2018-12-22 10:39:00 +00:00
item . onClick ( habbo . getClient ( ) , this , new Object [ 0 ] ) ;
2020-09-17 07:35:00 +02:00
item . setExtradata ( " 1 " ) ;
updateItemState ( item ) ;
Emulator . getThreading ( ) . run ( ( ) - > {
item . setExtradata ( " 0 " ) ;
updateItemState ( item ) ;
} , 2000 ) ;
2018-12-22 10:39:00 +00:00
break ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
}
}
}
}
2020-11-29 00:07:20 -05:00
/ * *
* 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 roomChatMessage The message to receive
* @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 ( ) ) ) {
RoomChatMessage staffChatMessage = new RoomChatMessage ( roomChatMessage ) ;
staffChatMessage . setMessage ( " [ " + Emulator . getTexts ( ) . getValue ( " hotel.room.tent.prefix " ) + " ] " + staffChatMessage . getMessage ( ) ) ;
final ServerMessage staffMessage = new RoomUserWhisperComposer ( staffChatMessage ) . compose ( ) ;
receivingHabbo . getClient ( ) . sendResponse ( staffMessage ) ;
}
}
2019-05-26 21:14:53 +03:00
public THashSet < RoomTile > getLockedTiles ( ) {
2018-09-28 19:25:00 +00:00
THashSet < RoomTile > lockedTiles = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
2018-07-06 13:30:00 +00:00
HabboItem item ;
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
item = iterator . value ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
if ( item . getBaseItem ( ) . getType ( ) ! = FurnitureType . FLOOR )
continue ;
boolean found = false ;
2019-05-26 21:14:53 +03:00
for ( RoomTile tile : lockedTiles ) {
if ( tile . x = = item . getX ( ) & &
tile . y = = item . getY ( ) ) {
2018-07-06 13:30:00 +00:00
found = true ;
break ;
}
}
2019-05-26 21:14:53 +03:00
if ( ! found ) {
if ( item . getRotation ( ) = = 0 | | item . getRotation ( ) = = 4 ) {
for ( short y = 0 ; y < item . getBaseItem ( ) . getLength ( ) ; y + + ) {
for ( short x = 0 ; x < item . getBaseItem ( ) . getWidth ( ) ; x + + ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( ( short ) ( item . getX ( ) + x ) , ( short ) ( item . getY ( ) + y ) ) ;
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
lockedTiles . add ( tile ) ;
}
}
}
2019-05-26 21:14:53 +03:00
} else {
for ( short y = 0 ; y < item . getBaseItem ( ) . getWidth ( ) ; y + + ) {
for ( short x = 0 ; x < item . getBaseItem ( ) . getLength ( ) ; x + + ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( ( short ) ( item . getX ( ) + x ) , ( short ) ( item . getY ( ) + y ) ) ;
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
lockedTiles . add ( tile ) ;
}
}
}
}
}
}
return lockedTiles ;
}
@Deprecated
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getItemsAt ( int x , int y ) {
RoomTile tile = this . getLayout ( ) . getTile ( ( short ) x , ( short ) y ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2018-07-06 13:30:00 +00:00
return this . getItemsAt ( tile ) ;
}
2018-09-28 19:25:00 +00:00
return new THashSet < > ( 0 ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getItemsAt ( RoomTile tile ) {
2020-08-16 03:01:37 +02:00
return getItemsAt ( tile , false ) ;
}
public THashSet < HabboItem > getItemsAt ( RoomTile tile , boolean returnOnFirst ) {
2019-09-27 20:15:21 +03:00
THashSet < HabboItem > items = new THashSet < > ( 0 ) ;
if ( tile = = null )
return items ;
2019-05-26 21:14:53 +03:00
if ( this . loaded ) {
2020-11-02 03:10:13 +01:00
THashSet < HabboItem > cachedItems = this . tileCache . get ( tile ) ;
if ( cachedItems ! = null )
return cachedItems ;
2018-07-06 13:30:00 +00:00
}
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
2018-07-06 13:30:00 +00:00
HabboItem item ;
2019-05-26 21:14:53 +03:00
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
item = iterator . value ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
2019-05-18 18:47:28 +03:00
if ( item = = null )
continue ;
2018-07-06 13:30:00 +00:00
if ( item . getBaseItem ( ) . getType ( ) ! = FurnitureType . FLOOR )
continue ;
2020-08-16 03:01:37 +02:00
int width , length ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
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 {
width = item . getBaseItem ( ) . getLength ( ) > 0 ? item . getBaseItem ( ) . getLength ( ) : 1 ;
length = item . getBaseItem ( ) . getWidth ( ) > 0 ? item . getBaseItem ( ) . getWidth ( ) : 1 ;
}
if ( ! ( tile . x > = item . getX ( ) & & tile . x < = item . getX ( ) + width - 1 & & tile . y > = item . getY ( ) & & tile . y < = item . getY ( ) + length - 1 ) )
continue ;
items . add ( item ) ;
if ( returnOnFirst ) {
return items ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
if ( this . loaded ) {
2018-07-06 13:30:00 +00:00
this . tileCache . put ( tile , items ) ;
}
return items ;
}
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getItemsAt ( int x , int y , double minZ ) {
2018-09-28 19:25:00 +00:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . getItemsAt ( x , y ) ) {
if ( item . getZ ( ) < minZ )
2018-07-06 13:30:00 +00:00
continue ;
2020-08-16 03:01:37 +02:00
items . add ( item ) ;
2018-07-06 13:30:00 +00:00
}
return items ;
}
2019-05-26 21:14:53 +03:00
public THashSet < HabboItem > getItemsAt ( Class < ? extends HabboItem > type , int x , int y ) {
2018-09-28 19:25:00 +00:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
for ( HabboItem item : this . getItemsAt ( x , y ) ) {
if ( ! item . getClass ( ) . equals ( type ) )
continue ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
items . add ( item ) ;
2018-07-06 13:30:00 +00:00
}
return items ;
}
2019-05-26 21:14:53 +03:00
public boolean hasItemsAt ( int x , int y ) {
2020-08-16 03:01:37 +02:00
RoomTile tile = this . getLayout ( ) . getTile ( ( short ) x , ( short ) y ) ;
2018-12-22 10:39:00 +00:00
2020-08-16 03:01:37 +02:00
if ( tile = = null )
return false ;
2018-12-22 10:39:00 +00:00
2020-08-16 03:01:37 +02:00
return this . getItemsAt ( tile , true ) . size ( ) > 0 ;
2018-12-22 10:39:00 +00:00
}
2019-05-26 21:14:53 +03:00
public HabboItem getTopItemAt ( int x , int y ) {
2018-07-06 13:30:00 +00:00
return this . getTopItemAt ( x , y , null ) ;
}
2019-05-26 21:14:53 +03:00
public HabboItem getTopItemAt ( int x , int y , HabboItem exclude ) {
2020-08-16 03:01:37 +02:00
RoomTile tile = this . getLayout ( ) . getTile ( ( short ) x , ( short ) y ) ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
if ( tile = = null )
return null ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
HabboItem highestItem = null ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
for ( HabboItem item : this . getItemsAt ( x , y ) ) {
if ( exclude ! = null & & exclude = = item )
2018-07-06 13:30:00 +00:00
continue ;
2020-08-16 03:01:37 +02:00
if ( highestItem ! = null & & highestItem . getZ ( ) + Item . getCurrentHeight ( highestItem ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
continue ;
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
highestItem = item ;
2018-07-06 13:30:00 +00:00
}
2020-08-16 03:01:37 +02:00
return highestItem ;
2018-07-06 13:30:00 +00:00
}
2020-10-15 03:47:34 +02:00
public HabboItem getTopItemAt ( THashSet < RoomTile > tiles , HabboItem exclude ) {
HabboItem highestItem = null ;
for ( RoomTile tile : tiles ) {
if ( tile = = null )
continue ;
for ( HabboItem item : this . getItemsAt ( tile . x , tile . y ) ) {
if ( exclude ! = null & & exclude = = item )
continue ;
if ( highestItem ! = null & & highestItem . getZ ( ) + Item . getCurrentHeight ( highestItem ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
continue ;
highestItem = item ;
}
}
return highestItem ;
}
2019-05-26 21:14:53 +03:00
public double getTopHeightAt ( int x , int y ) {
2019-03-18 01:22:00 +00:00
HabboItem item = this . getTopItemAt ( x , y ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( item ! = null )
2019-05-12 08:59:01 +01:00
return ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 13:30:00 +00:00
else
return this . layout . getHeightAtSquare ( x , y ) ;
}
@Deprecated
2019-05-26 21:14:53 +03:00
public HabboItem getLowestChair ( int x , int y ) {
2019-05-27 16:26:01 +03:00
if ( this . layout = = null ) return null ;
2019-05-26 21:14:53 +03:00
RoomTile tile = this . layout . getTile ( ( short ) x , ( short ) y ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( tile ! = null ) {
2019-03-18 01:22:00 +00:00
return this . getLowestChair ( tile ) ;
2018-07-06 13:30:00 +00:00
}
return null ;
}
2019-05-26 21:14:53 +03:00
public HabboItem getLowestChair ( RoomTile tile ) {
2018-07-06 13:30:00 +00:00
HabboItem lowestChair = null ;
THashSet < HabboItem > items = this . getItemsAt ( tile ) ;
2019-05-26 21:14:53 +03:00
if ( items ! = null & & ! items . isEmpty ( ) ) {
for ( HabboItem item : items ) {
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
if ( ! item . getBaseItem ( ) . allowSit ( ) )
continue ;
if ( lowestChair ! = null & & lowestChair . getZ ( ) < item . getZ ( ) )
continue ;
lowestChair = item ;
2018-07-06 13:30:00 +00:00
}
}
return lowestChair ;
}
2020-10-15 08:35:59 +02:00
public HabboItem getTallestChair ( RoomTile tile ) {
HabboItem lowestChair = null ;
THashSet < HabboItem > items = this . getItemsAt ( tile ) ;
if ( items ! = null & & ! items . isEmpty ( ) ) {
for ( HabboItem item : items ) {
if ( ! item . getBaseItem ( ) . allowSit ( ) )
continue ;
2020-10-15 08:43:35 +02:00
if ( lowestChair ! = null & & lowestChair . getZ ( ) + Item . getCurrentHeight ( lowestChair ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
2020-10-15 08:35:59 +02:00
continue ;
lowestChair = item ;
}
}
return lowestChair ;
}
2019-05-26 21:14:53 +03:00
public double getStackHeight ( short x , short y , boolean calculateHeightmap , HabboItem exclude ) {
2020-08-16 03:01:37 +02:00
2019-05-26 21:14:53 +03:00
if ( x < 0 | | y < 0 | | this . layout = = null )
2018-12-22 10:39:00 +00:00
return calculateHeightmap ? Short . MAX_VALUE : 0 . 0 ;
2020-09-03 22:08:24 +02:00
2020-09-03 22:07:45 +02:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureStackHeightEvent . class , true ) ) {
FurnitureStackHeightEvent event = Emulator . getPluginManager ( ) . fireEvent ( new FurnitureStackHeightEvent ( x , y , this ) ) ;
if ( event . hasPluginHelper ( ) ) {
return calculateHeightmap ? event . getHeight ( ) * 256 . 0D : event . getHeight ( ) ;
}
}
2018-07-06 13:30:00 +00:00
double height = this . layout . getHeightAtSquare ( x , y ) ;
boolean canStack = true ;
2018-12-22 10:39:00 +00:00
2020-08-16 03:01:37 +02:00
THashSet < HabboItem > stackHelpers = this . getItemsAt ( InteractionStackHelper . class , x , y ) ;
if ( stackHelpers . size ( ) > 0 ) {
for ( HabboItem item : stackHelpers ) {
if ( item = = exclude ) continue ;
return calculateHeightmap ? item . getZ ( ) * 256 . 0D : item . getZ ( ) ;
2018-07-06 13:30:00 +00:00
}
2020-08-16 03:01:37 +02:00
}
2018-07-06 13:30:00 +00:00
2020-08-16 03:01:37 +02:00
HabboItem item = this . getTopItemAt ( x , y , exclude ) ;
if ( item ! = null ) {
canStack = item . getBaseItem ( ) . allowStack ( ) ;
2020-10-16 05:50:57 +02:00
height = item . getZ ( ) + ( item . getBaseItem ( ) . allowSit ( ) ? 0 : Item . getCurrentHeight ( item ) ) ;
2020-08-16 03:01:37 +02:00
}
2019-05-12 08:59:01 +01:00
2020-10-15 08:35:59 +02:00
/ * HabboItem lowestChair = this . getLowestChair ( x , y ) ;
2020-08-16 03:01:37 +02:00
if ( lowestChair ! = null & & lowestChair ! = exclude ) {
canStack = true ;
height = lowestChair . getZ ( ) ;
2020-10-15 08:35:59 +02:00
} * /
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( calculateHeightmap ) {
2018-07-06 13:30:00 +00:00
return ( canStack ? height * 256 . 0D : Short . MAX_VALUE ) ;
}
2018-12-22 10:39:00 +00:00
return canStack ? height : - 1 ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public double getStackHeight ( short x , short y , boolean calculateHeightmap ) {
2018-12-22 10:39:00 +00:00
return this . getStackHeight ( x , y , calculateHeightmap , null ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean hasObjectTypeAt ( Class < ? > type , int x , int y ) {
2018-07-06 13:30:00 +00:00
THashSet < HabboItem > items = this . getItemsAt ( x , y ) ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : items ) {
if ( item . getClass ( ) = = type ) {
2018-07-06 13:30:00 +00:00
return true ;
}
}
return false ;
}
2019-05-26 21:14:53 +03:00
public boolean canSitOrLayAt ( int x , int y ) {
if ( this . hasHabbosAt ( x , y ) )
2018-07-06 13:30:00 +00:00
return false ;
2019-03-18 01:22:00 +00:00
THashSet < HabboItem > items = this . getItemsAt ( x , y ) ;
2018-07-06 13:30:00 +00:00
2019-03-18 01:22:00 +00:00
return this . canSitAt ( items ) | | this . canLayAt ( items ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean canSitAt ( int x , int y ) {
if ( this . hasHabbosAt ( x , y ) )
2018-07-06 13:30:00 +00:00
return false ;
return this . canSitAt ( this . getItemsAt ( x , y ) ) ;
}
2019-05-26 21:14:53 +03:00
boolean canWalkAt ( RoomTile roomTile ) {
if ( roomTile = = null ) {
2018-07-06 13:30:00 +00:00
return false ;
}
2018-11-17 13:28:00 +00:00
if ( roomTile . state = = RoomTileState . INVALID )
2018-07-06 13:30:00 +00:00
return false ;
HabboItem topItem = null ;
boolean canWalk = true ;
THashSet < HabboItem > items = this . getItemsAt ( roomTile ) ;
2019-05-26 21:14:53 +03:00
if ( items ! = null ) {
for ( HabboItem item : items ) {
if ( topItem = = null ) {
2018-07-06 13:30:00 +00:00
topItem = item ;
}
2019-05-26 21:14:53 +03:00
if ( item . getZ ( ) > topItem . getZ ( ) ) {
2018-07-06 13:30:00 +00:00
topItem = item ;
canWalk = topItem . isWalkable ( ) | | topItem . getBaseItem ( ) . allowWalk ( ) ;
2019-05-26 21:14:53 +03:00
} else if ( item . getZ ( ) = = topItem . getZ ( ) & & canWalk ) {
if ( ( ! topItem . isWalkable ( ) & & ! topItem . getBaseItem ( ) . allowWalk ( ) ) | | ( ! item . getBaseItem ( ) . allowWalk ( ) & & ! item . isWalkable ( ) ) ) {
2018-07-06 13:30:00 +00:00
canWalk = false ;
}
}
}
}
return canWalk ;
}
2019-05-26 21:14:53 +03:00
boolean canSitAt ( THashSet < HabboItem > items ) {
2018-07-06 13:30:00 +00:00
if ( items = = null )
return false ;
2020-10-15 08:35:59 +02:00
HabboItem tallestItem = null ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( HabboItem item : items ) {
2020-10-15 08:35:59 +02:00
if ( tallestItem ! = null & & tallestItem . getZ ( ) + Item . getCurrentHeight ( tallestItem ) > item . getZ ( ) + Item . getCurrentHeight ( item ) )
continue ;
2018-07-06 13:30:00 +00:00
2020-10-15 08:35:59 +02:00
tallestItem = item ;
2018-07-06 13:30:00 +00:00
}
2020-10-15 08:35:59 +02:00
if ( tallestItem = = null )
2018-07-06 13:30:00 +00:00
return false ;
2020-10-15 08:35:59 +02:00
return tallestItem . getBaseItem ( ) . allowSit ( ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean canLayAt ( int x , int y ) {
2018-07-06 13:30:00 +00:00
return this . canLayAt ( this . getItemsAt ( x , y ) ) ;
}
2019-05-26 21:14:53 +03:00
boolean canLayAt ( THashSet < HabboItem > items ) {
2018-07-06 13:30:00 +00:00
if ( items = = null | | items . isEmpty ( ) )
return true ;
HabboItem topItem = null ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : items ) {
if ( ( topItem = = null | | item . getZ ( ) > topItem . getZ ( ) ) ) {
2018-07-06 13:30:00 +00:00
topItem = item ;
}
}
return ( topItem = = null | | topItem . getBaseItem ( ) . allowLay ( ) ) ;
}
2019-05-26 21:14:53 +03:00
public RoomTile getRandomWalkableTile ( ) {
for ( int i = 0 ; i < 10 ; i + + ) {
2018-07-06 13:30:00 +00:00
RoomTile tile = this . layout . getTile ( ( short ) ( Math . random ( ) * this . layout . getMapSizeX ( ) ) , ( short ) ( Math . random ( ) * this . layout . getMapSizeY ( ) ) ) ;
2019-08-05 19:59:52 +03:00
if ( tile ! = null & & tile . getState ( ) ! = RoomTileState . BLOCKED & & tile . getState ( ) ! = RoomTileState . INVALID ) {
2018-07-06 13:30:00 +00:00
return tile ;
}
}
return null ;
}
2019-05-26 21:14:53 +03:00
public Habbo getHabbo ( String username ) {
for ( Habbo habbo : this . getHabbos ( ) ) {
2018-07-06 13:30:00 +00:00
if ( habbo . getHabboInfo ( ) . getUsername ( ) . equalsIgnoreCase ( username ) )
return habbo ;
}
return null ;
}
2019-05-26 21:14:53 +03:00
public Habbo getHabbo ( RoomUnit roomUnit ) {
for ( Habbo habbo : this . getHabbos ( ) ) {
2018-07-06 13:30:00 +00:00
if ( habbo . getRoomUnit ( ) = = roomUnit )
return habbo ;
}
return null ;
}
2019-05-26 21:14:53 +03:00
public Habbo getHabbo ( int userId ) {
2018-07-06 13:30:00 +00:00
return this . currentHabbos . get ( userId ) ;
}
2019-05-26 21:14:53 +03:00
public Habbo getHabboByRoomUnitId ( int roomUnitId ) {
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( habbo . getRoomUnit ( ) . getId ( ) = = roomUnitId )
2018-07-06 13:30:00 +00:00
return habbo ;
}
return null ;
}
2019-05-26 21:14:53 +03:00
public void sendComposer ( ServerMessage message ) {
2020-05-13 20:55:07 +02:00
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( habbo . getClient ( ) = = null ) {
this . removeHabbo ( habbo , true ) ;
continue ;
2020-05-09 21:56:52 +02:00
}
2020-05-13 20:55:07 +02:00
habbo . getClient ( ) . sendResponse ( message ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void sendComposerToHabbosWithRights ( ServerMessage message ) {
2020-05-13 20:55:07 +02:00
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( this . hasRights ( habbo ) ) {
habbo . getClient ( ) . sendResponse ( message ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
public void petChat ( ServerMessage message ) {
2020-05-13 20:55:07 +02:00
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( ! habbo . getHabboStats ( ) . ignorePets )
habbo . getClient ( ) . sendResponse ( message ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void botChat ( ServerMessage message ) {
2020-05-10 01:04:26 +02:00
if ( message = = null ) {
return ;
}
2020-05-13 20:55:07 +02:00
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( ! habbo . getHabboStats ( ) . ignoreBots )
habbo . getClient ( ) . sendResponse ( message ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private void loadRights ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . rights . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT user_id FROM room_rights WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
this . rights . add ( set . getInt ( " user_id " ) ) ;
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
private void loadBans ( Connection connection ) {
2018-07-06 13:30:00 +00:00
this . bannedHabbos . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT users.username, users.id, room_bans.* FROM room_bans INNER JOIN users ON room_bans.user_id = users.id WHERE ends > ? AND room_bans.room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , Emulator . getIntUnixTimestamp ( ) ) ;
statement . setInt ( 2 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
if ( this . bannedHabbos . containsKey ( set . getInt ( " user_id " ) ) )
continue ;
this . bannedHabbos . put ( set . getInt ( " user_id " ) , new RoomBan ( set ) ) ;
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2020-11-24 14:40:42 +01:00
public RoomRightLevels getGuildRightLevel ( Habbo habbo ) {
2019-05-26 21:14:53 +03:00
if ( this . guild > 0 & & habbo . getHabboStats ( ) . hasGuild ( this . guild ) ) {
2018-07-06 13:30:00 +00:00
Guild guild = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . guild ) ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getOnlyAdmins ( guild ) . get ( habbo . getHabboInfo ( ) . getId ( ) ) ! = null )
2020-11-24 14:40:42 +01:00
return RoomRightLevels . GUILD_ADMIN ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( guild . getRights ( ) ) {
2020-11-24 14:40:42 +01:00
return RoomRightLevels . GUILD_RIGHTS ;
2018-07-06 13:30:00 +00:00
}
}
2020-11-24 14:40:42 +01:00
return RoomRightLevels . NONE ;
}
/ * *
* @deprecated Deprecated since 2 . 5 . 0 . Use { @link # getGuildRightLevel ( Habbo ) } instead .
* /
@Deprecated
public int guildRightLevel ( Habbo habbo ) {
return this . getGuildRightLevel ( habbo ) . level ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean isOwner ( Habbo habbo ) {
2018-09-12 16:45:00 +00:00
return habbo . getHabboInfo ( ) . getId ( ) = = this . ownerId | | habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public boolean hasRights ( Habbo habbo ) {
2019-03-18 01:22:00 +00:00
return this . isOwner ( habbo ) | | this . rights . contains ( habbo . getHabboInfo ( ) . getId ( ) ) | | ( habbo . getRoomUnit ( ) . getRightsLevel ( ) ! = RoomRightLevels . NONE & & this . currentHabbos . containsKey ( habbo . getHabboInfo ( ) . getId ( ) ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void giveRights ( Habbo habbo ) {
if ( habbo ! = null ) {
2018-07-06 13:30:00 +00:00
this . giveRights ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public void giveRights ( int userId ) {
2018-07-06 13:30:00 +00:00
if ( this . rights . contains ( userId ) )
return ;
2019-05-26 21:14:53 +03:00
if ( this . rights . add ( userId ) ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO room_rights VALUES (?, ?) " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
Habbo habbo = this . getHabbo ( userId ) ;
2019-05-26 21:14:53 +03:00
if ( habbo ! = null ) {
2018-07-06 13:30:00 +00:00
this . refreshRightsForHabbo ( habbo ) ;
this . sendComposer ( new RoomAddRightsListComposer ( this , habbo . getHabboInfo ( ) . getId ( ) , habbo . getHabboInfo ( ) . getUsername ( ) ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-07-06 13:30:00 +00:00
Habbo owner = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( this . ownerId ) ;
2019-05-26 21:14:53 +03:00
if ( owner ! = null ) {
2018-07-06 13:30:00 +00:00
MessengerBuddy buddy = owner . getMessenger ( ) . getFriend ( userId ) ;
2019-05-26 21:14:53 +03:00
if ( buddy ! = null ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RoomAddRightsListComposer ( this , userId , buddy . getUsername ( ) ) . compose ( ) ) ;
}
}
}
}
2019-05-26 21:14:53 +03:00
public void removeRights ( int userId ) {
2018-07-06 13:30:00 +00:00
Habbo habbo = this . getHabbo ( userId ) ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . fireEvent ( new UserRightsTakenEvent ( this . getHabbo ( this . getOwnerId ( ) ) , userId , habbo ) ) . isCancelled ( ) )
2018-07-06 13:30:00 +00:00
return ;
this . sendComposer ( new RoomRemoveRightsListComposer ( this , userId ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
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 = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
if ( habbo ! = null ) {
2018-09-28 19:25:00 +00:00
habbo . getRoomUnit ( ) . setRightsLevel ( RoomRightLevels . NONE ) ;
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . FLAT_CONTROL ) ;
2018-07-06 13:30:00 +00:00
this . refreshRightsForHabbo ( habbo ) ;
}
}
2019-05-26 21:14:53 +03:00
public void removeAllRights ( ) {
2018-07-06 13:30:00 +00:00
this . rights . clear ( ) ;
2019-05-26 21:14:53 +03:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_rights WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
this . refreshRightsInRoom ( ) ;
}
2019-05-26 21:14:53 +03:00
void refreshRightsInRoom ( ) {
2018-07-06 13:30:00 +00:00
Room room = this ;
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) = = room ) {
2019-03-18 01:22:00 +00:00
this . refreshRightsForHabbo ( habbo ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
public void refreshRightsForHabbo ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
HabboItem item ;
RoomRightLevels flatCtrl = RoomRightLevels . NONE ;
2019-05-26 21:14:53 +03:00
if ( habbo . getHabboStats ( ) . isRentingSpace ( ) ) {
2018-07-06 13:30:00 +00:00
item = this . getHabboItem ( habbo . getHabboStats ( ) . getRentedItemId ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( item ! = null ) {
2018-07-06 13:30:00 +00:00
return ;
}
}
2019-05-26 21:14:53 +03:00
if ( habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new RoomOwnerComposer ( ) ) ;
flatCtrl = RoomRightLevels . MODERATOR ;
2019-05-26 21:14:53 +03:00
} else if ( this . isOwner ( habbo ) ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new RoomOwnerComposer ( ) ) ;
flatCtrl = RoomRightLevels . MODERATOR ;
2019-05-26 21:14:53 +03:00
} else if ( this . hasRights ( habbo ) & & ! this . hasGuild ( ) ) {
2018-07-06 13:30:00 +00:00
flatCtrl = RoomRightLevels . RIGHTS ;
2019-05-26 21:14:53 +03:00
} else if ( this . hasGuild ( ) ) {
2020-11-24 14:40:42 +01:00
flatCtrl = this . getGuildRightLevel ( habbo ) ;
2018-07-06 13:30:00 +00:00
}
habbo . getClient ( ) . sendResponse ( new RoomRightsComposer ( flatCtrl ) ) ;
2018-09-12 16:45:00 +00:00
habbo . getRoomUnit ( ) . setStatus ( RoomUnitStatus . FLAT_CONTROL , flatCtrl . level + " " ) ;
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . setRightsLevel ( flatCtrl ) ;
2018-09-28 19:25:00 +00:00
habbo . getRoomUnit ( ) . statusUpdate ( true ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( flatCtrl . equals ( RoomRightLevels . MODERATOR ) ) {
2018-07-06 13:30:00 +00:00
habbo . getClient ( ) . sendResponse ( new RoomRightsListComposer ( this ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public THashMap < Integer , String > getUsersWithRights ( ) {
2018-09-28 19:25:00 +00:00
THashMap < Integer , String > rightsMap = new THashMap < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ! this . rights . isEmpty ( ) ) {
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " SELECT users.username AS username, users.id as user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . id ) ;
2019-05-26 21:14:53 +03:00
try ( ResultSet set = statement . executeQuery ( ) ) {
while ( set . next ( ) ) {
2018-07-06 13:30:00 +00:00
rightsMap . put ( set . getInt ( " user_id " ) , set . getString ( " username " ) ) ;
}
}
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
return rightsMap ;
}
2019-05-26 21:14:53 +03:00
public void unbanHabbo ( int userId ) {
2018-07-06 13:30:00 +00:00
RoomBan ban = this . bannedHabbos . remove ( userId ) ;
2019-05-26 21:14:53 +03:00
if ( ban ! = null ) {
2018-07-06 13:30:00 +00:00
ban . delete ( ) ;
}
this . sendComposer ( new RoomUserUnbannedComposer ( this , userId ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
public boolean isBanned ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
RoomBan ban = this . bannedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) ;
2018-09-12 16:45:00 +00:00
boolean banned = ban ! = null & & ban . endTimestamp > Emulator . getIntUnixTimestamp ( ) & & ! habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) & & ! habbo . hasPermission ( " acc_enteranyroom " ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( ! banned & & ban ! = null ) {
2018-07-06 13:30:00 +00:00
this . unbanHabbo ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
return banned ;
}
2019-05-26 21:14:53 +03:00
public TIntObjectHashMap < RoomBan > getBannedHabbos ( ) {
2018-07-06 13:30:00 +00:00
return this . bannedHabbos ;
}
2019-05-26 21:14:53 +03:00
public void addRoomBan ( RoomBan roomBan ) {
2018-07-06 13:30:00 +00:00
this . bannedHabbos . put ( roomBan . userId , roomBan ) ;
}
2019-05-26 21:14:53 +03:00
public void makeSit ( Habbo habbo ) {
2019-06-16 13:52:27 +03:00
if ( habbo . getRoomUnit ( ) = = null ) return ;
if ( habbo . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . SIT ) | | ! habbo . getRoomUnit ( ) . canForcePosture ( ) ) {
2018-07-06 13:30:00 +00:00
return ;
}
this . dance ( habbo , DanceType . NONE ) ;
habbo . getRoomUnit ( ) . cmdSit = true ;
habbo . getRoomUnit ( ) . setBodyRotation ( RoomUserRotation . values ( ) [ habbo . getRoomUnit ( ) . getBodyRotation ( ) . getValue ( ) - habbo . getRoomUnit ( ) . getBodyRotation ( ) . getValue ( ) % 2 ] ) ;
2018-09-12 16:45:00 +00:00
habbo . getRoomUnit ( ) . setStatus ( RoomUnitStatus . SIT , 0 . 5 + " " ) ;
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RoomUserStatusComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
}
2020-03-13 17:00:48 +00:00
public void makeStand ( Habbo habbo ) {
if ( habbo . getRoomUnit ( ) = = null ) return ;
2020-03-13 17:03:30 +00:00
2020-03-13 17:00:48 +00:00
HabboItem item = this . getTopItemAt ( habbo . getRoomUnit ( ) . getX ( ) , habbo . getRoomUnit ( ) . getY ( ) ) ;
2020-03-13 17:03:30 +00:00
if ( item = = null | | ! item . getBaseItem ( ) . allowSit ( ) | | ! item . getBaseItem ( ) . allowLay ( ) ) {
2020-03-13 17:00:48 +00:00
habbo . getRoomUnit ( ) . cmdStand = true ;
habbo . getRoomUnit ( ) . setBodyRotation ( RoomUserRotation . values ( ) [ habbo . getRoomUnit ( ) . getBodyRotation ( ) . getValue ( ) - habbo . getRoomUnit ( ) . getBodyRotation ( ) . getValue ( ) % 2 ] ) ;
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . SIT ) ;
this . sendComposer ( new RoomUserStatusComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public void giveEffect ( Habbo habbo , int effectId , int duration ) {
if ( this . currentHabbos . containsKey ( habbo . getHabboInfo ( ) . getId ( ) ) ) {
2019-03-18 01:22:00 +00:00
this . giveEffect ( habbo . getRoomUnit ( ) , effectId , duration ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void giveEffect ( RoomUnit roomUnit , int effectId , int duration ) {
if ( duration = = - 1 | | duration = = Integer . MAX_VALUE ) {
2019-03-18 01:22:00 +00:00
duration = Integer . MAX_VALUE ;
2019-05-26 21:14:53 +03:00
} else {
2019-03-18 01:22:00 +00:00
duration + = Emulator . getIntUnixTimestamp ( ) ;
}
2019-05-26 21:14:53 +03:00
if ( this . allowEffects & & roomUnit ! = null ) {
2019-03-18 01:22:00 +00:00
roomUnit . setEffectId ( effectId , duration ) ;
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RoomUserEffectComposer ( roomUnit ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public void giveHandItem ( Habbo habbo , int handItem ) {
2019-03-18 01:22:00 +00:00
this . giveHandItem ( habbo . getRoomUnit ( ) , handItem ) ;
2018-12-22 10:39:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void giveHandItem ( RoomUnit roomUnit , int handItem ) {
2018-12-22 10:39:00 +00:00
roomUnit . setHandItem ( handItem ) ;
this . sendComposer ( new RoomUserHandItemComposer ( roomUnit ) . compose ( ) ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void updateItem ( HabboItem item ) {
if ( this . isLoaded ( ) ) {
if ( item ! = null & & item . getRoomId ( ) = = this . id ) {
if ( item . getBaseItem ( ) ! = null ) {
if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new FloorItemUpdateComposer ( item ) . compose ( ) ) ;
this . updateTiles ( this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ) ;
2019-05-26 21:14:53 +03:00
} else if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . WALL ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new WallItemUpdateComposer ( item ) . compose ( ) ) ;
}
}
}
}
}
2019-05-26 21:14:53 +03:00
public void updateItemState ( HabboItem item ) {
if ( ! item . isLimited ( ) ) {
2018-09-12 16:45:00 +00:00
this . sendComposer ( new ItemStateComposer ( item ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
} else {
2018-09-12 16:45:00 +00:00
this . sendComposer ( new FloorItemUpdateComposer ( item ) . compose ( ) ) ;
}
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR ) {
2019-06-13 17:17:20 +03:00
if ( this . layout = = null ) return ;
2018-07-06 13:30:00 +00:00
this . updateTiles ( this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ) ;
2020-10-15 03:47:34 +02:00
if ( item instanceof InteractionMultiHeight ) {
( ( InteractionMultiHeight ) item ) . updateUnitsOnItem ( this ) ;
}
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public int getUserFurniCount ( int userId ) {
2018-07-06 13:30:00 +00:00
return this . furniOwnerCount . get ( userId ) ;
}
2019-05-26 22:33:51 +03:00
public int getUserUniqueFurniCount ( int userId ) {
THashSet < Item > items = new THashSet < > ( ) ;
for ( HabboItem item : this . roomItems . valueCollection ( ) ) {
if ( ! items . contains ( item . getBaseItem ( ) ) & & item . getUserId ( ) = = userId ) items . add ( item . getBaseItem ( ) ) ;
}
return items . size ( ) ;
}
2019-05-26 21:14:53 +03:00
public void ejectUserFurni ( int userId ) {
2018-09-28 19:25:00 +00:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
2019-05-26 21:14:53 +03:00
if ( iterator . value ( ) . getUserId ( ) = = userId ) {
2018-07-06 13:30:00 +00:00
items . add ( iterator . value ( ) ) ;
iterator . value ( ) . setRoomId ( 0 ) ;
}
}
Habbo habbo = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( userId ) ;
2019-05-26 21:14:53 +03:00
if ( habbo ! = null ) {
2018-07-06 13:30:00 +00:00
habbo . getInventory ( ) . getItemsComponent ( ) . addItems ( items ) ;
habbo . getClient ( ) . sendResponse ( new AddHabboItemComposer ( items ) ) ;
}
2019-05-26 21:14:53 +03:00
for ( HabboItem i : items ) {
2018-07-06 13:30:00 +00:00
this . pickUpItem ( i , null ) ;
}
}
2019-05-26 21:14:53 +03:00
public void ejectUserItem ( HabboItem item ) {
2018-07-06 13:30:00 +00:00
this . pickUpItem ( item , null ) ;
}
2018-07-08 21:32:00 +00:00
2019-05-26 21:14:53 +03:00
public void ejectAll ( ) {
2018-07-06 13:30:00 +00:00
this . ejectAll ( null ) ;
}
2018-07-08 21:32:00 +00:00
2019-05-26 21:14:53 +03:00
public void ejectAll ( Habbo habbo ) {
2018-09-28 19:25:00 +00:00
THashMap < Integer , THashSet < HabboItem > > userItemsMap = new THashMap < > ( ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
synchronized ( this . roomItems ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
if ( habbo ! = null & & iterator . value ( ) . getUserId ( ) = = habbo . getHabboInfo ( ) . getId ( ) )
continue ;
2020-01-22 11:24:29 +02:00
if ( iterator . value ( ) instanceof InteractionPostIt )
continue ;
2018-07-06 13:30:00 +00:00
2020-01-22 11:24:29 +02:00
userItemsMap . computeIfAbsent ( iterator . value ( ) . getUserId ( ) , k - > new THashSet < > ( ) ) . add ( iterator . value ( ) ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
for ( Map . Entry < Integer , THashSet < HabboItem > > entrySet : userItemsMap . entrySet ( ) ) {
for ( HabboItem i : entrySet . getValue ( ) ) {
2018-07-06 13:30:00 +00:00
this . pickUpItem ( i , null ) ;
}
Habbo user = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( entrySet . getKey ( ) ) ;
2019-05-26 21:14:53 +03:00
if ( user ! = null ) {
2018-07-06 13:30:00 +00:00
user . getInventory ( ) . getItemsComponent ( ) . addItems ( entrySet . getValue ( ) ) ;
user . getClient ( ) . sendResponse ( new AddHabboItemComposer ( entrySet . getValue ( ) ) ) ;
}
}
}
2019-05-26 21:14:53 +03:00
public void refreshGuild ( Guild guild ) {
if ( guild . getRoomId ( ) = = this . id ) {
2019-05-18 16:44:12 +03:00
THashSet < GuildMember > members = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuildMembers ( guild . getId ( ) ) ;
2018-07-06 13:30:00 +00:00
2019-05-26 21:14:53 +03:00
for ( Habbo habbo : this . getHabbos ( ) ) {
2019-05-18 16:44:12 +03:00
Optional < GuildMember > member = members . stream ( ) . filter ( m - > m . getUserId ( ) = = habbo . getHabboInfo ( ) . getId ( ) ) . findAny ( ) ;
if ( ! member . isPresent ( ) ) continue ;
habbo . getClient ( ) . sendResponse ( new GuildInfoComposer ( guild , habbo . getClient ( ) , false , member . get ( ) ) ) ;
2018-07-06 13:30:00 +00:00
}
}
this . refreshGuildRightsInRoom ( ) ;
}
2019-05-26 21:14:53 +03:00
public void refreshGuildColors ( Guild guild ) {
if ( guild . getRoomId ( ) = = this . id ) {
2018-07-06 13:30:00 +00:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
2019-05-26 21:14:53 +03:00
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; ) {
try {
2018-07-06 13:30:00 +00:00
iterator . advance ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( Exception e ) {
2018-07-06 13:30:00 +00:00
break ;
}
HabboItem habboItem = iterator . value ( ) ;
2019-05-26 21:14:53 +03:00
if ( habboItem instanceof InteractionGuildFurni ) {
2018-07-06 13:30:00 +00:00
if ( ( ( InteractionGuildFurni ) habboItem ) . getGuildId ( ) = = guild . getId ( ) )
this . updateItem ( habboItem ) ;
}
}
}
}
2019-05-26 21:14:53 +03:00
public void refreshGuildRightsInRoom ( ) {
for ( Habbo habbo : this . getHabbos ( ) ) {
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) = = this ) {
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . ownerId ) {
2020-06-05 04:12:49 -04:00
if ( ! ( habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) | | habbo . hasPermission ( Permission . ACC_MOVEROTATE ) ) )
2019-03-18 01:22:00 +00:00
this . refreshRightsForHabbo ( habbo ) ;
2018-07-06 13:30:00 +00:00
}
}
}
}
2019-05-26 21:14:53 +03:00
public void idle ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . setIdle ( ) ;
2020-01-24 20:34:27 +02:00
if ( habbo . getRoomUnit ( ) . getDanceType ( ) ! = DanceType . NONE ) {
this . dance ( habbo , DanceType . NONE ) ;
}
2018-07-06 13:30:00 +00:00
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2018-12-22 10:39:00 +00:00
WiredHandler . handle ( WiredTriggerType . IDLES , habbo . getRoomUnit ( ) , this , new Object [ ] { habbo } ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void unIdle ( Habbo habbo ) {
2019-08-11 12:26:19 +03:00
if ( habbo = = null | | habbo . getRoomUnit ( ) = = null ) return ;
2018-07-06 13:30:00 +00:00
habbo . getRoomUnit ( ) . resetIdleTimer ( ) ;
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2018-12-22 10:39:00 +00:00
WiredHandler . handle ( WiredTriggerType . UNIDLES , habbo . getRoomUnit ( ) , this , new Object [ ] { habbo } ) ;
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void dance ( Habbo habbo , DanceType danceType ) {
2018-09-12 16:45:00 +00:00
this . dance ( habbo . getRoomUnit ( ) , danceType ) ;
}
2019-05-26 21:14:53 +03:00
public void dance ( RoomUnit unit , DanceType danceType ) {
2020-10-15 04:56:48 +02:00
if ( unit . getDanceType ( ) ! = danceType ) {
boolean isDancing = ! unit . getDanceType ( ) . equals ( DanceType . NONE ) ;
unit . setDanceType ( danceType ) ;
this . sendComposer ( new RoomUserDanceComposer ( unit ) . compose ( ) ) ;
if ( danceType . equals ( DanceType . NONE ) & & isDancing ) {
WiredHandler . handle ( WiredTriggerType . STOPS_DANCING , unit , this , new Object [ ] { unit } ) ;
} else if ( ! danceType . equals ( DanceType . NONE ) & & ! isDancing ) {
WiredHandler . handle ( WiredTriggerType . STARTS_DANCING , unit , this , new Object [ ] { unit } ) ;
}
2019-03-18 01:22:00 +00:00
}
2018-07-06 13:30:00 +00:00
}
2019-05-26 21:14:53 +03:00
public void addToWordFilter ( String word ) {
synchronized ( this . wordFilterWords ) {
2018-07-06 13:30:00 +00:00
if ( this . wordFilterWords . contains ( word ) )
return ;
2019-05-26 21:14:53 +03:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT IGNORE INTO room_wordfilter VALUES (?, ?) " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . getId ( ) ) ;
statement . setString ( 2 , word ) ;
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2019-03-18 01:22:00 +00:00
return ;
2018-07-06 13:30:00 +00:00
}
2019-03-18 01:22:00 +00:00
this . wordFilterWords . add ( word ) ;
2018-07-06 13:30:00 +00:00
}
}
2019-05-26 21:14:53 +03:00
public void removeFromWordFilter ( String word ) {
synchronized ( this . wordFilterWords ) {
2018-07-06 13:30:00 +00:00
this . wordFilterWords . remove ( word ) ;
2019-05-26 21:14:53 +03:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_wordfilter WHERE room_id = ? AND word = ? " ) ) {
2018-07-06 13:30:00 +00:00
statement . setInt ( 1 , this . getId ( ) ) ;
statement . setString ( 2 , word ) ;
statement . execute ( ) ;
2019-05-26 21:14:53 +03:00
} catch ( SQLException e ) {
2020-05-04 22:24:09 +02:00
LOGGER . error ( " Caught SQL exception " , e ) ;
2018-07-06 13:30:00 +00:00
}
}
}
2019-05-26 21:14:53 +03:00
public void handleWordQuiz ( Habbo habbo , String answer ) {
synchronized ( this . userVotes ) {
if ( ! this . wordQuiz . isEmpty ( ) & & ! this . hasVotedInWordQuiz ( habbo ) ) {
2018-07-06 13:30:00 +00:00
answer = answer . replace ( " : " , " " ) ;
2019-05-26 21:14:53 +03:00
if ( answer . equals ( " 0 " ) ) {
2018-07-06 13:30:00 +00:00
this . noVotes + + ;
2019-05-26 21:14:53 +03:00
} else if ( answer . equals ( " 1 " ) ) {
2018-07-06 13:30:00 +00:00
this . yesVotes + + ;
}
this . sendComposer ( new SimplePollAnswerComposer ( habbo . getHabboInfo ( ) . getId ( ) , answer , this . noVotes , this . yesVotes ) . compose ( ) ) ;
this . userVotes . add ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
}
}
2019-05-26 21:14:53 +03:00
public void startWordQuiz ( String question , int duration ) {
if ( ! this . hasActiveWordQuiz ( ) ) {
2018-07-06 13:30:00 +00:00
this . wordQuiz = question ;
this . noVotes = 0 ;
this . yesVotes = 0 ;
this . userVotes . clear ( ) ;
this . wordQuizEnd = Emulator . getIntUnixTimestamp ( ) + ( duration / 1000 ) ;
this . sendComposer ( new SimplePollStartComposer ( duration , question ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public boolean hasActiveWordQuiz ( ) {
2018-07-06 13:30:00 +00:00
return Emulator . getIntUnixTimestamp ( ) < this . wordQuizEnd ;
}
2019-05-26 21:14:53 +03:00
public boolean hasVotedInWordQuiz ( Habbo habbo ) {
2018-07-06 13:30:00 +00:00
return this . userVotes . contains ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
2019-05-26 21:14:53 +03:00
public void alert ( String message ) {
2018-07-06 13:30:00 +00:00
this . sendComposer ( new GenericAlertComposer ( message ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
public int itemCount ( ) {
2018-07-06 13:30:00 +00:00
return this . roomItems . size ( ) ;
}
2019-05-26 21:14:53 +03:00
public void setJukeBoxActive ( boolean jukeBoxActive ) {
2018-07-06 13:30:00 +00:00
this . jukeboxActive = jukeBoxActive ;
this . needsUpdate = true ;
}
2018-09-28 19:25:00 +00:00
2019-05-26 21:14:53 +03:00
public boolean isHideWired ( ) {
2018-09-28 19:25:00 +00:00
return this . hideWired ;
}
2019-05-26 21:14:53 +03:00
public void setHideWired ( boolean hideWired ) {
2018-09-28 19:25:00 +00:00
this . hideWired = hideWired ;
2019-05-26 21:14:53 +03:00
if ( this . hideWired ) {
2018-09-28 19:25:00 +00:00
ServerMessage response = null ;
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . roomSpecialTypes . getTriggers ( ) ) {
2018-09-28 19:25:00 +00:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . roomSpecialTypes . getEffects ( ) ) {
2018-09-28 19:25:00 +00:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . roomSpecialTypes . getConditions ( ) ) {
2018-12-22 10:39:00 +00:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
for ( HabboItem item : this . roomSpecialTypes . getExtras ( ) ) {
2018-09-28 19:25:00 +00:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
2019-05-26 21:14:53 +03:00
} else {
2018-09-28 19:25:00 +00:00
this . sendComposer ( new RoomFloorItemsComposer ( this . furniOwnerNames , this . roomSpecialTypes . getTriggers ( ) ) . compose ( ) ) ;
this . sendComposer ( new RoomFloorItemsComposer ( this . furniOwnerNames , this . roomSpecialTypes . getEffects ( ) ) . compose ( ) ) ;
this . sendComposer ( new RoomFloorItemsComposer ( this . furniOwnerNames , this . roomSpecialTypes . getConditions ( ) ) . compose ( ) ) ;
2018-12-22 10:39:00 +00:00
this . sendComposer ( new RoomFloorItemsComposer ( this . furniOwnerNames , this . roomSpecialTypes . getExtras ( ) ) . compose ( ) ) ;
}
}
2019-05-26 21:14:53 +03:00
public FurnitureMovementError canPlaceFurnitureAt ( HabboItem item , Habbo habbo , RoomTile tile , int rotation ) {
2019-12-23 15:12:13 +02:00
if ( this . itemCount ( ) > = Room . MAXIMUM_FURNI ) {
return FurnitureMovementError . MAX_ITEMS ;
}
2019-04-21 23:42:00 +00:00
rotation % = 8 ;
2020-11-24 14:40:42 +01:00
if ( this . hasRights ( habbo ) | | this . getGuildRightLevel ( habbo ) . isEqualOrGreaterThan ( RoomRightLevels . GUILD_RIGHTS ) | | habbo . hasPermission ( Permission . ACC_MOVEROTATE ) ) {
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . NONE ;
}
2019-05-26 21:14:53 +03:00
if ( habbo . getHabboStats ( ) . isRentingSpace ( ) ) {
2018-12-22 10:39:00 +00:00
HabboItem rentSpace = this . getHabboItem ( habbo . getHabboStats ( ) . rentedItemId ) ;
2019-05-26 21:14:53 +03:00
if ( rentSpace ! = null ) {
if ( ! RoomLayout . squareInSquare ( RoomLayout . getRectangle ( rentSpace . getX ( ) , rentSpace . getY ( ) , rentSpace . getBaseItem ( ) . getWidth ( ) , rentSpace . getBaseItem ( ) . getLength ( ) , rentSpace . getRotation ( ) ) , RoomLayout . getRectangle ( tile . x , tile . y , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ) ) {
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . NO_RIGHTS ;
2019-05-26 21:14:53 +03:00
} else {
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . NONE ;
}
}
2018-09-28 19:25:00 +00:00
}
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . NO_RIGHTS ;
2018-09-28 19:25:00 +00:00
}
2018-12-22 10:39:00 +00:00
2019-05-26 21:14:53 +03:00
public FurnitureMovementError furnitureFitsAt ( RoomTile tile , HabboItem item , int rotation ) {
2020-10-15 03:47:34 +02:00
return furnitureFitsAt ( tile , item , rotation , true ) ;
}
public FurnitureMovementError furnitureFitsAt ( RoomTile tile , HabboItem item , int rotation , boolean checkForUnits ) {
2019-05-26 21:14:53 +03:00
if ( ! this . layout . fitsOnMap ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) )
2019-05-03 04:08:27 +01:00
return FurnitureMovementError . INVALID_MOVE ;
2020-02-27 22:53:06 +02:00
if ( item instanceof InteractionStackHelper ) return FurnitureMovementError . NONE ;
2018-12-22 10:39:00 +00:00
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
2019-05-04 02:25:43 +01:00
for ( RoomTile t : occupiedTiles ) {
2020-10-15 03:47:34 +02:00
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 ;
2019-05-04 02:25:43 +01:00
}
2018-12-22 10:39:00 +00:00
2020-02-27 22:53:06 +02:00
List < Pair < RoomTile , THashSet < HabboItem > > > tileFurniList = new ArrayList < > ( ) ;
for ( RoomTile t : occupiedTiles ) {
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
2018-12-22 10:39:00 +00:00
2020-02-27 22:53:06 +02:00
HabboItem topItem = this . getTopItemAt ( t . x , t . y , item ) ;
if ( topItem ! = null & & ! topItem . getBaseItem ( ) . allowStack ( ) & & ! t . getAllowStack ( ) ) {
2019-05-09 03:02:41 +01:00
return FurnitureMovementError . CANT_STACK ;
}
2018-12-22 10:39:00 +00:00
}
2020-02-27 22:53:06 +02:00
if ( ! item . canStackAt ( this , tileFurniList ) ) {
return FurnitureMovementError . CANT_STACK ;
}
2019-04-21 23:42:00 +00:00
return FurnitureMovementError . NONE ;
}
2019-05-26 21:14:53 +03:00
2020-10-08 12:34:14 -05:00
public FurnitureMovementError placeFloorFurniAt ( HabboItem item , RoomTile tile , int rotation , Habbo owner ) {
2020-09-01 00:22:21 +02:00
boolean pluginHelper = false ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePlacedEvent . class , true ) ) {
2020-09-01 00:22:21 +02:00
FurniturePlacedEvent event = Emulator . getPluginManager ( ) . fireEvent ( new FurniturePlacedEvent ( item , owner , tile ) ) ;
2019-04-21 23:42:00 +00:00
2020-09-01 00:22:21 +02:00
if ( event . isCancelled ( ) ) {
2019-04-21 23:42:00 +00:00
return FurnitureMovementError . CANCEL_PLUGIN_PLACE ;
2020-09-01 00:22:21 +02:00
}
pluginHelper = event . hasPluginHelper ( ) ;
2019-04-21 23:42:00 +00:00
}
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
FurnitureMovementError fits = furnitureFitsAt ( tile , item , rotation ) ;
2020-09-01 00:22:21 +02:00
if ( ! fits . equals ( FurnitureMovementError . NONE ) & & ! pluginHelper ) {
2019-04-21 23:42:00 +00:00
return fits ;
}
2020-06-08 17:38:22 +02:00
double height = tile . getStackHeight ( ) ;
2020-10-15 08:57:12 +02:00
for ( RoomTile tile2 : occupiedTiles ) {
double sHeight = tile2 . getStackHeight ( ) ;
if ( sHeight > height ) {
height = sHeight ;
}
}
2020-06-08 17:38:22 +02:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureBuildheightEvent . class , true ) ) {
2020-10-08 12:34:14 -05:00
FurnitureBuildheightEvent event = Emulator . getPluginManager ( ) . fireEvent ( new FurnitureBuildheightEvent ( item , owner , 0 . 00 , height ) ) ;
2020-06-08 17:38:22 +02:00
if ( event . hasChangedHeight ( ) ) {
height = event . getUpdatedHeight ( ) ;
}
}
item . setZ ( height ) ;
2018-12-22 10:39:00 +00:00
item . setX ( tile . x ) ;
item . setY ( tile . y ) ;
item . setRotation ( rotation ) ;
2019-05-26 21:14:53 +03:00
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) & & owner ! = null ) {
2018-12-22 10:39:00 +00:00
this . furniOwnerNames . put ( item . getUserId ( ) , owner . getHabboInfo ( ) . getUsername ( ) ) ;
}
item . needsUpdate ( true ) ;
this . addHabboItem ( item ) ;
item . setRoomId ( this . id ) ;
item . onPlace ( this ) ;
this . updateTiles ( occupiedTiles ) ;
this . sendComposer ( new AddFloorItemComposer ( item , this . getFurniOwnerName ( item . getUserId ( ) ) ) . compose ( ) ) ;
2019-05-26 21:14:53 +03:00
for ( RoomTile t : occupiedTiles ) {
2018-12-22 10:39:00 +00:00
this . updateHabbosAt ( t . x , t . y ) ;
2019-05-12 10:41:57 -04:00
this . updateBotsAt ( t . x , t . y ) ;
2018-12-22 10:39:00 +00:00
}
Emulator . getThreading ( ) . run ( item ) ;
return FurnitureMovementError . NONE ;
}
2019-05-26 21:14:53 +03:00
public FurnitureMovementError placeWallFurniAt ( HabboItem item , String wallPosition , Habbo owner ) {
2020-11-24 14:40:42 +01:00
if ( ! ( this . hasRights ( owner ) | | this . getGuildRightLevel ( owner ) . isEqualOrGreaterThan ( RoomRightLevels . GUILD_RIGHTS ) ) ) {
2019-03-18 01:22:00 +00:00
return FurnitureMovementError . NO_RIGHTS ;
}
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePlacedEvent . class , true ) ) {
2018-12-22 10:39:00 +00:00
Event furniturePlacedEvent = new FurniturePlacedEvent ( item , owner , null ) ;
Emulator . getPluginManager ( ) . fireEvent ( furniturePlacedEvent ) ;
2019-05-26 21:14:53 +03:00
if ( furniturePlacedEvent . isCancelled ( ) )
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . CANCEL_PLUGIN_PLACE ;
}
item . setWallPosition ( wallPosition ) ;
2019-05-26 21:14:53 +03:00
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) & & owner ! = null ) {
2018-12-22 10:39:00 +00:00
this . furniOwnerNames . put ( item . getUserId ( ) , owner . getHabboInfo ( ) . getUsername ( ) ) ;
}
this . sendComposer ( new AddWallItemComposer ( item , this . getFurniOwnerName ( item . getUserId ( ) ) ) . compose ( ) ) ;
item . needsUpdate ( true ) ;
this . addHabboItem ( item ) ;
item . setRoomId ( this . id ) ;
item . onPlace ( this ) ;
Emulator . getThreading ( ) . run ( item ) ;
return FurnitureMovementError . NONE ;
}
2019-05-26 21:14:53 +03:00
public FurnitureMovementError moveFurniTo ( HabboItem item , RoomTile tile , int rotation , Habbo actor ) {
2020-10-15 03:47:34 +02:00
return moveFurniTo ( item , tile , rotation , actor , true ) ;
}
public FurnitureMovementError moveFurniTo ( HabboItem item , RoomTile tile , int rotation , Habbo actor , boolean sendUpdates ) {
2018-12-22 10:39:00 +00:00
RoomTile oldLocation = this . layout . getTile ( item . getX ( ) , item . getY ( ) ) ;
2020-09-01 00:22:21 +02:00
boolean pluginHelper = false ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureMovedEvent . class , true ) ) {
2020-09-01 00:22:21 +02:00
FurnitureMovedEvent event = Emulator . getPluginManager ( ) . fireEvent ( new FurnitureMovedEvent ( item , actor , oldLocation , tile ) ) ;
if ( event . isCancelled ( ) ) {
2018-12-22 10:39:00 +00:00
return FurnitureMovementError . CANCEL_PLUGIN_MOVE ;
2020-09-01 00:22:21 +02:00
}
pluginHelper = event . hasPluginHelper ( ) ;
2018-12-22 10:39:00 +00:00
}
2019-03-18 01:22:00 +00:00
boolean magicTile = item instanceof InteractionStackHelper ;
2020-03-04 18:45:33 +02:00
Optional < HabboItem > stackHelper = this . getItemsAt ( tile ) . stream ( ) . filter ( i - > i instanceof InteractionStackHelper ) . findAny ( ) ;
2018-12-22 10:39:00 +00:00
//Check if can be placed at new position
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
2020-03-04 18:57:04 +02:00
2020-10-15 03:47:34 +02:00
HabboItem topItem = this . getTopItemAt ( occupiedTiles , null ) ;
2020-09-01 00:22:21 +02:00
if ( ! stackHelper . isPresent ( ) & & ! pluginHelper ) {
2020-10-15 09:19:05 +02:00
if ( oldLocation ! = tile ) {
2020-03-04 18:45:33 +02:00
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 ) ) ) )
return FurnitureMovementError . CANT_STACK ;
2020-04-27 01:53:59 +02:00
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 ;
2020-03-04 18:45:33 +02:00
}
2018-12-22 10:39:00 +00:00
}
2020-03-04 18:45:33 +02:00
List < Pair < RoomTile , THashSet < HabboItem > > > tileFurniList = new ArrayList < > ( ) ;
for ( RoomTile t : occupiedTiles ) {
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
}
2018-12-22 10:39:00 +00:00
2020-03-04 18:45:33 +02:00
if ( ! magicTile & & ! item . canStackAt ( this , tileFurniList ) ) {
return FurnitureMovementError . CANT_STACK ;
}
2018-12-22 10:39:00 +00:00
}
THashSet < RoomTile > oldOccupiedTiles = this . layout . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
int oldRotation = item . getRotation ( ) ;
2019-05-26 21:14:53 +03:00
if ( oldRotation ! = rotation ) {
2020-10-22 02:09:35 +02:00
item . setRotation ( rotation ) ;
2019-05-26 21:14:53 +03:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureRotatedEvent . class , true ) ) {
2019-04-21 23:42:00 +00:00
Event furnitureRotatedEvent = new FurnitureRotatedEvent ( item , actor , oldRotation ) ;
Emulator . getPluginManager ( ) . fireEvent ( furnitureRotatedEvent ) ;
2019-05-26 21:14:53 +03:00
if ( furnitureRotatedEvent . isCancelled ( ) ) {
2019-04-21 23:42:00 +00:00
item . setRotation ( oldRotation ) ;
return FurnitureMovementError . CANCEL_PLUGIN_ROTATE ;
}
2018-12-22 10:39:00 +00:00
}
2020-10-22 02:09:35 +02:00
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 ;
}
// )
2018-12-22 10:39:00 +00:00
}
//Place at new position
2020-01-28 15:13:32 +02:00
2020-03-04 18:45:33 +02:00
double height ;
if ( stackHelper . isPresent ( ) ) {
2020-10-08 12:34:14 -05:00
height = stackHelper . get ( ) . getExtradata ( ) . isEmpty ( ) ? Double . parseDouble ( " 0.0 " ) : ( Double . parseDouble ( stackHelper . get ( ) . getExtradata ( ) ) / 100 ) ;
2020-10-22 02:09:35 +02:00
} else if ( item = = topItem ) {
2020-03-04 18:45:33 +02:00
height = item . getZ ( ) ;
} else {
height = this . getStackHeight ( tile . x , tile . y , false , item ) ;
2020-10-15 03:47:34 +02:00
for ( RoomTile til : occupiedTiles ) {
double sHeight = this . getStackHeight ( til . x , til . y , false , item ) ;
if ( sHeight > height ) {
height = sHeight ;
}
}
2020-03-04 18:45:33 +02:00
}
2020-06-08 17:38:22 +02:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureBuildheightEvent . class , true ) ) {
2020-10-08 12:34:14 -05:00
FurnitureBuildheightEvent event = Emulator . getPluginManager ( ) . fireEvent ( new FurnitureBuildheightEvent ( item , actor , 0 . 00 , height ) ) ;
2020-06-08 17:38:22 +02:00
if ( event . hasChangedHeight ( ) ) {
height = event . getUpdatedHeight ( ) ;
}
}
2020-10-22 02:09:35 +02:00
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
2020-01-28 15:13:32 +02:00
2018-12-22 10:39:00 +00:00
item . setX ( tile . x ) ;
item . setY ( tile . y ) ;
2019-08-30 02:25:54 +01:00
item . setZ ( height ) ;
2019-05-26 21:14:53 +03:00
if ( magicTile ) {
2019-03-18 01:22:00 +00:00
item . setZ ( tile . z ) ;
2019-04-21 23:42:00 +00:00
item . setExtradata ( " " + item . getZ ( ) * 100 ) ;
2019-03-18 01:22:00 +00:00
}
2020-10-22 02:09:35 +02:00
if ( item . getZ ( ) > MAXIMUM_FURNI_HEIGHT ) {
item . setZ ( MAXIMUM_FURNI_HEIGHT ) ;
2018-12-22 10:39:00 +00:00
}
2019-03-18 01:22:00 +00:00
//Update Furniture
item . onMove ( this , oldLocation , tile ) ;
item . needsUpdate ( true ) ;
Emulator . getThreading ( ) . run ( item ) ;
2020-10-15 03:47:34 +02:00
if ( sendUpdates ) {
this . sendComposer ( new FloorItemUpdateComposer ( item ) . compose ( ) ) ;
}
2018-12-22 10:39:00 +00:00
//Update old & new tiles
occupiedTiles . removeAll ( oldOccupiedTiles ) ;
2019-03-18 01:22:00 +00:00
occupiedTiles . addAll ( oldOccupiedTiles ) ;
2018-12-22 10:39:00 +00:00
this . updateTiles ( occupiedTiles ) ;
//Update Habbos at old position
2019-05-26 21:14:53 +03:00
for ( RoomTile t : occupiedTiles ) {
2020-02-01 13:22:35 +02:00
this . updateHabbosAt (
t . x ,
t . y ,
this . getHabbosAt ( t . x , t . y )
2020-10-15 09:09:48 +02:00
/ * . stream ( )
. filter ( h - > ! h . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . MOVE ) | | h . getRoomUnit ( ) . getGoal ( ) = = t )
. collect ( Collectors . toCollection ( THashSet : : new ) ) * /
2020-02-01 13:22:35 +02:00
) ;
2019-05-12 10:41:57 -04:00
this . updateBotsAt ( t . x , t . y ) ;
2018-12-22 10:39:00 +00:00
}
return FurnitureMovementError . NONE ;
}
2019-05-26 21:14:53 +03:00
public FurnitureMovementError slideFurniTo ( HabboItem item , RoomTile tile , int rotation ) {
2019-04-21 23:42:00 +00:00
RoomTile oldLocation = this . layout . getTile ( item . getX ( ) , item . getY ( ) ) ;
HabboItem topItem = this . getTopItemAt ( tile . x , tile . y ) ;
boolean magicTile = item instanceof InteractionStackHelper ;
//Check if can be placed at new position
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
List < Pair < RoomTile , THashSet < HabboItem > > > tileFurniList = new ArrayList < > ( ) ;
2019-05-26 21:14:53 +03:00
for ( RoomTile t : occupiedTiles ) {
2019-04-21 23:42:00 +00:00
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
}
2019-05-26 21:14:53 +03:00
if ( ! magicTile & & ! item . canStackAt ( this , tileFurniList ) ) {
2019-04-21 23:42:00 +00:00
return FurnitureMovementError . CANT_STACK ;
}
THashSet < RoomTile > oldOccupiedTiles = this . layout . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
int oldRotation = item . getRotation ( ) ;
item . setRotation ( rotation ) ;
//Place at new position
2019-05-26 21:14:53 +03:00
if ( magicTile ) {
2019-04-21 23:42:00 +00:00
item . setZ ( tile . z ) ;
item . setExtradata ( " " + item . getZ ( ) * 100 ) ;
}
2020-10-22 02:09:35 +02:00
if ( item . getZ ( ) > MAXIMUM_FURNI_HEIGHT ) {
item . setZ ( MAXIMUM_FURNI_HEIGHT ) ;
2019-04-21 23:42:00 +00:00
}
2019-05-01 02:55:21 +01:00
double offset = this . getStackHeight ( tile . x , tile . y , false , item ) - item . getZ ( ) ;
this . sendComposer ( new FloorItemOnRollerComposer ( item , null , tile , offset , this ) . compose ( ) ) ;
2019-04-21 23:42:00 +00:00
//Update Habbos at old position
2019-05-26 21:14:53 +03:00
for ( RoomTile t : occupiedTiles ) {
2019-04-21 23:42:00 +00:00
this . updateHabbosAt ( t . x , t . y ) ;
2019-05-12 10:41:57 -04:00
this . updateBotsAt ( t . x , t . y ) ;
2019-04-21 23:42:00 +00:00
}
return FurnitureMovementError . NONE ;
}
2019-05-18 18:32:13 +03:00
public THashSet < RoomUnit > getRoomUnits ( ) {
2020-10-15 03:47:34 +02:00
return getRoomUnits ( null ) ;
}
public THashSet < RoomUnit > getRoomUnits ( RoomTile atTile ) {
2019-05-18 18:32:13 +03:00
THashSet < RoomUnit > units = new THashSet < > ( ) ;
2018-12-22 10:39:00 +00:00
2019-05-18 18:32:13 +03:00
for ( Habbo habbo : this . currentHabbos . values ( ) ) {
2020-10-15 03:47:34 +02:00
if ( habbo ! = null & & habbo . getRoomUnit ( ) ! = null & & habbo . getRoomUnit ( ) . getRoom ( ) ! = null & & habbo . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) & & ( atTile = = null | | habbo . getRoomUnit ( ) . getCurrentLocation ( ) = = atTile ) ) {
2019-05-18 18:32:13 +03:00
units . add ( habbo . getRoomUnit ( ) ) ;
}
}
for ( Pet pet : this . currentPets . valueCollection ( ) ) {
2020-10-15 03:47:34 +02:00
if ( pet ! = null & & pet . getRoomUnit ( ) ! = null & & pet . getRoomUnit ( ) . getRoom ( ) ! = null & & pet . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) & & ( atTile = = null | | pet . getRoomUnit ( ) . getCurrentLocation ( ) = = atTile ) ) {
2019-05-18 18:32:13 +03:00
units . add ( pet . getRoomUnit ( ) ) ;
}
}
for ( Bot bot : this . currentBots . valueCollection ( ) ) {
2020-10-15 03:47:34 +02:00
if ( bot ! = null & & bot . getRoomUnit ( ) ! = null & & bot . getRoomUnit ( ) . getRoom ( ) ! = null & & bot . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) & & ( atTile = = null | | bot . getRoomUnit ( ) . getCurrentLocation ( ) = = atTile ) ) {
2019-05-18 18:32:13 +03:00
units . add ( bot . getRoomUnit ( ) ) ;
}
}
return units ;
}
2020-10-12 11:18:52 +02:00
public Collection < RoomUnit > getRoomUnitsAt ( RoomTile tile ) {
THashSet < RoomUnit > roomUnits = getRoomUnits ( ) ;
return roomUnits . stream ( ) . filter ( unit - > unit . getCurrentLocation ( ) = = tile ) . collect ( Collectors . toSet ( ) ) ;
}
2020-11-24 14:40:42 +01:00
}