2018-07-06 15:30:00 +02: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 ;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.messenger.MessengerBuddy ;
2018-09-12 18:45:00 +02:00
import com.eu.habbo.habbohotel.permissions.Permission ;
2018-09-28 21:25:00 +02:00
import com.eu.habbo.habbohotel.pets.Pet ;
import com.eu.habbo.habbohotel.pets.PetManager ;
2019-05-13 05:11:27 +02:00
import com.eu.habbo.habbohotel.pets.RideablePet ;
2018-07-06 15:30:00 +02:00
import com.eu.habbo.habbohotel.users.* ;
import com.eu.habbo.habbohotel.wired.* ;
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 21:25:00 +02: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 15:30:00 +02: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 11:39:00 +01:00
import com.eu.habbo.plugin.events.furniture.* ;
2018-07-06 15:30:00 +02: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 ;
import com.eu.habbo.plugin.events.users.UserExitRoomEvent ;
import com.eu.habbo.plugin.events.users.UserIdleEvent ;
import com.eu.habbo.plugin.events.users.UserRightsTakenEvent ;
import com.eu.habbo.plugin.events.users.UserRolledEvent ;
2019-05-13 05:11:27 +02:00
import com.eu.habbo.threading.runnables.RoomUnitRidePet ;
2018-07-06 15:30:00 +02: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 11:39:00 +01:00
import org.apache.commons.math3.util.Pair ;
2018-07-06 15:30:00 +02: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 ;
public class Room implements Comparable < Room > , ISerialize , Runnable
{
//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 ;
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>] " ;
2018-09-28 21:25:00 +02:00
private static final TIntObjectHashMap < RoomMoodlightData > defaultMoodData = new TIntObjectHashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
static
{
for ( int i = 1 ; i < = 3 ; i + + )
{
RoomMoodlightData data = RoomMoodlightData . fromString ( " " ) ;
data . setId ( i ) ;
defaultMoodData . put ( i , data ) ;
}
}
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 02:22:00 +01:00
private volatile boolean hideWired ;
2018-07-06 15:30:00 +02:00
private final ConcurrentHashMap < Integer , Habbo > currentHabbos = new ConcurrentHashMap < > ( 3 ) ;
2018-09-28 21:25:00 +02:00
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 ) ) ;
2018-07-06 15:30:00 +02:00
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 THashMap < WiredHighscoreScoreType , THashMap < WiredHighscoreClearType , THashSet < WiredHighscoreData > > > wiredHighscoreData ;
private RoomPromotion promotion ;
private volatile boolean needsUpdate ;
private volatile boolean loaded ;
private volatile boolean preLoaded ;
2019-03-18 02:22:00 +01:00
private int idleCycles ;
2018-07-06 15:30:00 +02:00
private volatile int unitCounter ;
private volatile int rollerSpeed ;
2019-03-18 02:22:00 +01:00
private long rollerCycle = System . currentTimeMillis ( ) ;
2018-07-06 15:30:00 +02:00
private volatile int lastTimerReset = Emulator . getIntUnixTimestamp ( ) ;
private volatile boolean muted ;
private RoomSpecialTypes roomSpecialTypes ;
private final Object loadLock = new Object ( ) ;
public final Object roomUnitLock = new Object ( ) ;
//Use appropriately. Could potentially cause memory leaks when used incorrectly.
public volatile boolean preventUnloading = false ;
public volatile boolean preventUncaching = false ;
2019-03-18 02:22:00 +01:00
public THashMap < Short , TIntArrayList > waterTiles ;
2018-09-28 21:25:00 +02:00
public final ConcurrentHashMap < RoomTile , THashSet < HabboItem > > tileCache = new ConcurrentHashMap < > ( ) ;
public ConcurrentSet < ServerMessage > scheduledComposers = new ConcurrentSet < > ( ) ;
public ConcurrentSet < Runnable > scheduledTasks = new ConcurrentSet < > ( ) ;
2018-07-06 15:30:00 +02:00
public String wordQuiz = " " ;
public int noVotes = 0 ;
public int yesVotes = 0 ;
public int wordQuizEnd = 0 ;
public final List < Integer > userVotes ;
public ScheduledFuture roomCycleTask ;
private TraxManager traxManager ;
2019-03-18 02:22:00 +01:00
private long cycleTimestamp ;
2018-07-06 15:30:00 +02:00
public Room ( ResultSet set ) throws SQLException
{
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-07 00:28:00 +02:00
this . hideWired = set . getString ( " hidewired " ) . equals ( " 1 " ) ;
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
this . bannedHabbos = new TIntObjectHashMap < > ( ) ;
2018-07-06 15:30:00 +02: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 )
{
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , Emulator . getIntUnixTimestamp ( ) ) ;
try ( ResultSet promotionSet = statement . executeQuery ( ) )
{
this . promoted = false ;
if ( promotionSet . next ( ) )
{
this . promoted = true ;
this . promotion = new RoomPromotion ( this , promotionSet ) ;
}
}
}
this . loadBans ( connection ) ;
}
2019-05-24 00:57:22 +02:00
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-07-06 15:30:00 +02: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 21:25:00 +02:00
this . furniOwnerNames = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
2018-07-06 15:30:00 +02:00
this . furniOwnerCount = TCollections . synchronizedMap ( new TIntIntHashMap ( 0 ) ) ;
2018-09-28 21:25:00 +02:00
this . roomItems = TCollections . synchronizedMap ( new TIntObjectHashMap < > ( 0 ) ) ;
this . wordFilterWords = new THashSet < > ( 0 ) ;
this . moodlightData = new TIntObjectHashMap < > ( defaultMoodData ) ;
2018-07-06 15:30:00 +02:00
for ( String s : set . getString ( " moodlight_data " ) . split ( " ; " ) )
{
RoomMoodlightData data = RoomMoodlightData . fromString ( s ) ;
this . moodlightData . put ( data . getId ( ) , data ) ;
}
this . mutedHabbos = new TIntIntHashMap ( ) ;
2018-09-28 21:25:00 +02:00
this . games = new ConcurrentSet < > ( ) ;
2018-07-06 15:30:00 +02:00
2018-09-28 21:25:00 +02:00
this . activeTrades = new THashSet < > ( 0 ) ;
2018-07-06 15:30:00 +02:00
this . rights = new TIntArrayList ( ) ;
2018-09-28 21:25:00 +02:00
this . wiredHighscoreData = new THashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
this . userVotes = new ArrayList < > ( ) ;
}
public synchronized void loadData ( )
{
synchronized ( this . loadLock )
{
if ( ! this . preLoaded | | this . loaded )
return ;
this . preLoaded = false ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) )
{
synchronized ( this . roomUnitLock )
{
this . unitCounter = 0 ;
this . currentHabbos . clear ( ) ;
this . currentPets . clear ( ) ;
this . currentBots . clear ( ) ;
}
this . roomSpecialTypes = new RoomSpecialTypes ( ) ;
try
{
this . loadLayout ( ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadRights ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadItems ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadHeightmap ( ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadBots ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadPets ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadWordFilter ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
try
{
this . loadWiredData ( connection ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
this . idleCycles = 0 ;
this . loaded = true ;
this . roomCycleTask = Emulator . getThreading ( ) . getService ( ) . scheduleAtFixedRate ( this , 500 , 500 , TimeUnit . MILLISECONDS ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
this . traxManager = new TraxManager ( this ) ;
if ( this . jukeboxActive )
{
this . traxManager . play ( 0 ) ;
for ( HabboItem item : this . roomSpecialTypes . getItemsOfType ( InteractionJukeBox . class ) )
{
item . setExtradata ( " 1 " ) ;
this . updateItem ( item ) ;
}
}
}
Emulator . getPluginManager ( ) . fireEvent ( new RoomLoadedEvent ( this ) ) ;
}
private synchronized void loadLayout ( )
{
if ( this . layout = = null )
{
if ( this . overrideModel )
{
this . layout = Emulator . getGameEnvironment ( ) . getRoomManager ( ) . loadCustomLayout ( this ) ;
}
else
{
this . layout = Emulator . getGameEnvironment ( ) . getRoomManager ( ) . loadLayout ( this . layoutName , this ) ;
}
}
}
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 + + )
{
RoomTile tile = this . layout . getTile ( x , y ) ;
if ( tile ! = null )
{
this . updateTile ( tile ) ;
}
}
}
}
else
{
Emulator . getLogging ( ) . logErrorLine ( " Unknown Room Layout for Room (ID: " + this . id + " ) " ) ;
}
}
2019-05-24 00:57:22 +02:00
private synchronized void loadItems ( Connection connection )
2018-07-06 15:30:00 +02:00
{
this . roomItems . clear ( ) ;
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM items WHERE room_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
this . addHabboItem ( Emulator . getGameEnvironment ( ) . getItemManager ( ) . loadHabboItem ( set ) ) ;
}
}
}
2019-05-24 00:57:22 +02:00
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-07-06 15:30:00 +02:00
}
2019-05-24 00:57:22 +02:00
private synchronized void loadWiredData ( Connection connection )
2018-07-06 15:30:00 +02:00
{
2018-09-12 18:45:00 +02:00
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>'' " ) )
2018-07-06 15:30:00 +02:00
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
try
{
HabboItem item = this . getHabboItem ( set . getInt ( " id " ) ) ;
2019-03-18 02:22:00 +01:00
if ( item instanceof InteractionWired )
2018-07-06 15:30:00 +02:00
{
( ( InteractionWired ) item ) . loadWiredData ( set , this ) ;
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}
}
2019-05-24 00:57:22 +02:00
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-07-06 15:30:00 +02:00
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
2019-05-24 00:57:22 +02:00
private synchronized void loadBots ( Connection connection )
2018-07-06 15:30:00 +02:00
{
this . currentBots . clear ( ) ;
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 = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
Bot b = Emulator . getGameEnvironment ( ) . getBotManager ( ) . loadBot ( set ) ;
if ( b ! = null )
{
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 " ) ) ) ;
if ( b . getRoomUnit ( ) . getCurrentLocation ( ) = = null )
{
b . getRoomUnit ( ) . setLocation ( this . getLayout ( ) . getDoorTile ( ) ) ;
b . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( this . getLayout ( ) . getDoorDirection ( ) ) ) ;
}
else
{
b . getRoomUnit ( ) . setZ ( set . getDouble ( " z " ) ) ;
b . getRoomUnit ( ) . setRotation ( RoomUserRotation . values ( ) [ set . getInt ( " rot " ) ] ) ;
}
b . getRoomUnit ( ) . setRoomUnitType ( RoomUnitType . BOT ) ;
b . getRoomUnit ( ) . setDanceType ( DanceType . values ( ) [ set . getInt ( " dance " ) ] ) ;
2018-10-07 00:28:00 +02:00
//b.getRoomUnit().setCanWalk(set.getBoolean("freeroam"));
2018-07-06 15:30:00 +02:00
b . getRoomUnit ( ) . setInRoom ( true ) ;
2019-04-22 01:42:00 +02:00
this . giveEffect ( b . getRoomUnit ( ) , set . getInt ( " effect " ) , Integer . MAX_VALUE ) ;
2018-07-06 15:30:00 +02:00
this . addBot ( b ) ;
}
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
2019-05-24 00:57:22 +02:00
private synchronized void loadPets ( Connection connection )
2018-07-06 15:30:00 +02:00
{
this . currentPets . clear ( ) ;
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 = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
try
{
2018-09-12 18:45:00 +02:00
Pet pet = PetManager . loadPet ( set ) ;
2018-07-06 15:30:00 +02: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 " ) ) ) ;
if ( pet . getRoomUnit ( ) . getCurrentLocation ( ) = = null )
{
pet . getRoomUnit ( ) . setLocation ( this . getLayout ( ) . getDoorTile ( ) ) ;
pet . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( this . getLayout ( ) . getDoorDirection ( ) ) ) ;
}
else
{
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 " ) ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}
}
2019-05-24 00:57:22 +02:00
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-07-06 15:30:00 +02:00
}
2019-05-24 00:57:22 +02:00
private synchronized void loadWordFilter ( Connection connection )
2018-07-06 15:30:00 +02:00
{
this . wordFilterWords . clear ( ) ;
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT * FROM room_wordfilter WHERE room_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
this . wordFilterWords . add ( set . getString ( " word " ) ) ;
}
}
}
2019-05-24 00:57:22 +02:00
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-07-06 15:30:00 +02:00
}
public void updateTile ( RoomTile tile )
{
if ( tile ! = null )
{
tile . setStackHeight ( this . getStackHeight ( tile . x , tile . y , false ) ) ;
2018-11-17 14:28:00 +01:00
tile . setState ( this . calculateTileState ( tile ) ) ;
2018-07-06 15:30:00 +02:00
}
}
public void updateTiles ( THashSet < RoomTile > tiles )
{
for ( RoomTile tile : tiles )
{
this . tileCache . remove ( tile ) ;
tile . setStackHeight ( this . getStackHeight ( tile . x , tile . y , false ) ) ;
2018-11-17 14:28:00 +01:00
tile . setState ( this . calculateTileState ( tile ) ) ;
2018-07-06 15:30:00 +02:00
}
this . sendComposer ( new UpdateStackHeightComposer ( tiles ) . compose ( ) ) ;
}
2018-11-17 14:28:00 +01:00
private RoomTileState calculateTileState ( RoomTile tile )
2019-03-18 02:22:00 +01:00
{
return this . calculateTileState ( tile , null ) ;
}
private RoomTileState calculateTileState ( RoomTile tile , HabboItem exclude )
2018-11-17 14:28:00 +01:00
{
2019-05-18 15:14:21 +02:00
if ( tile = = null | | tile . state = = RoomTileState . INVALID )
2018-11-17 14:28:00 +01:00
return RoomTileState . INVALID ;
RoomTileState result = RoomTileState . OPEN ;
HabboItem lowestItem = null ;
2018-12-22 11:39:00 +01:00
HabboItem lowestChair = this . getLowestChair ( tile ) ;
2018-11-17 14:28:00 +01:00
for ( HabboItem item : this . getItemsAt ( tile ) )
{
2019-03-18 02:22:00 +01:00
if ( exclude ! = null & & item = = exclude ) continue ;
2018-11-17 14:28:00 +01:00
if ( lowestChair ! = null & & item . getZ ( ) > lowestChair . getZ ( ) + 1 . 5 )
{
continue ;
}
if ( lowestItem = = null | | lowestItem . getZ ( ) < item . getZ ( ) )
{
lowestItem = item ;
2019-03-18 02:22:00 +01:00
result = this . checkStateForItem ( lowestItem ) ;
2018-11-17 14:28:00 +01:00
}
else if ( lowestItem . getZ ( ) = = item . getZ ( ) )
{
if ( result = = RoomTileState . OPEN )
{
2019-03-18 02:22:00 +01:00
result = this . checkStateForItem ( item ) ;
2018-11-17 14:28:00 +01:00
}
}
}
2018-12-22 11:39:00 +01:00
if ( lowestChair ! = null ) return RoomTileState . SIT ;
2018-11-17 14:28:00 +01:00
return result ;
}
private RoomTileState checkStateForItem ( HabboItem item )
{
RoomTileState result = RoomTileState . BLOCKED ;
if ( item . isWalkable ( ) )
{
result = RoomTileState . OPEN ;
}
if ( item . getBaseItem ( ) . allowSit ( ) )
{
result = RoomTileState . SIT ;
}
if ( item . getBaseItem ( ) . allowLay ( ) )
{
result = RoomTileState . LAY ;
}
return result ;
}
2018-07-06 15:30:00 +02:00
public boolean tileWalkable ( RoomTile t )
{
return this . tileWalkable ( t . x , t . y ) ;
}
public boolean tileWalkable ( short x , short y )
{
boolean walkable = this . layout . tileWalkable ( x , y ) ;
2019-05-12 09:59:01 +02:00
RoomTile tile = this . getLayout ( ) . getTile ( x , y ) ;
2018-07-06 15:30:00 +02:00
2019-05-12 09:59:01 +02:00
if ( walkable & & tile ! = null )
2018-07-06 15:30:00 +02:00
{
2019-05-12 09:59:01 +02:00
if ( tile . hasUnits ( ) & & ! this . allowWalkthrough )
2018-07-06 15:30:00 +02:00
{
walkable = false ;
}
}
2018-09-28 21:25:00 +02:00
2019-05-12 09:59:01 +02:00
return walkable ;
2018-07-06 15:30:00 +02:00
}
public void pickUpItem ( HabboItem item , Habbo picker )
{
if ( item = = null )
return ;
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePickedUpEvent . class , true ) )
{
Event furniturePickedUpEvent = new FurniturePickedUpEvent ( item , picker ) ;
Emulator . getPluginManager ( ) . fireEvent ( furniturePickedUpEvent ) ;
if ( furniturePickedUpEvent . isCancelled ( ) )
return ;
}
this . removeHabboItem ( item . getId ( ) ) ;
item . onPickUp ( this ) ;
item . setRoomId ( 0 ) ;
item . needsUpdate ( true ) ;
if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR )
{
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
2018-09-28 21:25:00 +02:00
THashSet < RoomTile > updatedTiles = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
Rectangle rectangle = RoomLayout . getRectangle ( item . getX ( ) , item . getY ( ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
for ( short x = ( short ) rectangle . x ; x < rectangle . x + rectangle . getWidth ( ) ; x + + )
{
for ( short y = ( short ) rectangle . y ; y < rectangle . y + rectangle . getHeight ( ) ; y + + )
{
double stackHeight = this . getStackHeight ( x , y , false ) ;
RoomTile tile = this . layout . getTile ( x , y ) ;
if ( tile ! = null )
{
tile . setStackHeight ( stackHeight ) ;
updatedTiles . add ( tile ) ;
}
}
}
this . sendComposer ( new UpdateStackHeightComposer ( updatedTiles ) . compose ( ) ) ;
this . updateTiles ( updatedTiles ) ;
for ( RoomTile tile : updatedTiles )
{
this . updateHabbosAt ( tile . x , tile . y ) ;
2019-05-12 16:41:57 +02:00
this . updateBotsAt ( tile . x , tile . y ) ;
2018-07-06 15:30:00 +02:00
}
}
else if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . WALL )
{
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 14:28:00 +01:00
habbo . getClient ( ) . sendResponse ( new AddHabboItemComposer ( item ) ) ;
2018-07-06 15:30:00 +02:00
habbo . getClient ( ) . sendResponse ( new InventoryRefreshComposer ( ) ) ;
}
Emulator . getThreading ( ) . run ( item ) ;
}
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 + + )
{
this . updateHabbosAt ( i , j ) ;
}
}
}
public void updateHabbo ( Habbo habbo )
{
2019-03-18 02:22:00 +01:00
this . updateRoomUnit ( habbo . getRoomUnit ( ) ) ;
2018-12-22 11:39:00 +01:00
}
public void updateRoomUnit ( RoomUnit roomUnit )
{
HabboItem item = this . getTopItemAt ( roomUnit . getX ( ) , roomUnit . getY ( ) ) ;
2018-07-06 15:30:00 +02:00
2018-12-22 11:39:00 +01:00
if ( ( item = = null & & ! roomUnit . cmdSit ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowSit ( ) ) )
roomUnit . removeStatus ( RoomUnitStatus . SIT ) ;
2018-07-06 15:30:00 +02:00
2019-04-22 01:42:00 +02:00
double oldZ = roomUnit . getZ ( ) ;
2018-07-06 15:30:00 +02:00
if ( item ! = null )
{
if ( item . getBaseItem ( ) . allowSit ( ) )
{
2018-12-22 11:39:00 +01:00
roomUnit . setZ ( item . getZ ( ) ) ;
2018-07-06 15:30:00 +02:00
}
else
{
2019-05-12 09:59:01 +02:00
roomUnit . setZ ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 15:30:00 +02:00
}
2019-04-22 01:42:00 +02:00
if ( oldZ ! = roomUnit . getZ ( ) )
{
this . scheduledTasks . add ( new Runnable ( )
{
@Override
public void run ( )
{
try
{
item . onWalkOn ( roomUnit , Room . this , null ) ;
} catch ( Exception e )
{
}
}
} ) ;
}
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
this . sendComposer ( new RoomUserStatusComposer ( roomUnit ) . compose ( ) ) ;
2018-07-06 15:30:00 +02:00
}
public void updateHabbosAt ( short x , short y )
{
THashSet < Habbo > habbos = this . getHabbosAt ( x , y ) ;
HabboItem item = this . getTopItemAt ( x , y ) ;
2018-09-28 21:25:00 +02:00
THashSet < RoomUnit > roomUnits = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
for ( Habbo habbo : habbos )
{
if ( ( item = = null & & ! habbo . getRoomUnit ( ) . cmdSit ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowSit ( ) ) )
2018-09-12 18:45:00 +02:00
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . SIT ) ;
2018-07-06 15:30:00 +02:00
if ( ( item = = null & & ! habbo . getRoomUnit ( ) . cmdLay ) | | ( item ! = null & & ! item . getBaseItem ( ) . allowLay ( ) ) )
2018-09-12 18:45:00 +02:00
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . LAY ) ;
2018-07-06 15:30:00 +02:00
if ( item ! = null )
{
2019-05-12 20:45:50 +02:00
if ( item . getBaseItem ( ) . allowSit ( ) | | item . getBaseItem ( ) . allowLay ( ) )
2018-07-06 15:30:00 +02:00
{
habbo . getRoomUnit ( ) . setZ ( item . getZ ( ) ) ;
2018-12-22 11:39:00 +01:00
habbo . getRoomUnit ( ) . setPreviousLocationZ ( item . getZ ( ) ) ;
habbo . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( item . getRotation ( ) ) ) ;
2018-07-06 15:30:00 +02:00
}
else
{
2019-05-12 09:59:01 +02:00
habbo . getRoomUnit ( ) . setZ ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 15:30:00 +02:00
}
}
else
{
habbo . getRoomUnit ( ) . setZ ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ) ;
2019-04-22 01:42:00 +02:00
habbo . getRoomUnit ( ) . setPreviousLocationZ ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ) ;
2018-07-06 15:30:00 +02:00
}
roomUnits . add ( habbo . getRoomUnit ( ) ) ;
}
2019-03-18 02:22:00 +01:00
if ( ! roomUnits . isEmpty ( ) )
{
this . sendComposer ( new RoomUserStatusComposer ( roomUnits , true ) . compose ( ) ) ;
}
2018-07-06 15:30:00 +02:00
}
2019-05-12 16:41:57 +02:00
private void updateBotsAt ( short x , short y )
{
HabboItem topItem = this . getTopItemAt ( x , y ) ;
THashSet < RoomUnit > roomUnits = new THashSet < > ( ) ;
for ( Bot bot : this . getBotsAt ( this . layout . getTile ( x , y ) ) ) {
if ( topItem ! = null )
{
if ( topItem . getBaseItem ( ) . allowSit ( ) )
{
bot . getRoomUnit ( ) . setZ ( topItem . getZ ( ) ) ;
bot . getRoomUnit ( ) . setPreviousLocationZ ( topItem . getZ ( ) ) ;
bot . getRoomUnit ( ) . setRotation ( RoomUserRotation . fromValue ( topItem . getRotation ( ) ) ) ;
} else {
bot . getRoomUnit ( ) . setZ ( topItem . getZ ( ) + topItem . getBaseItem ( ) . getHeight ( ) ) ;
if ( topItem . getBaseItem ( ) . allowLay ( ) )
{
bot . getRoomUnit ( ) . setStatus ( RoomUnitStatus . LAY , ( topItem . getZ ( ) + topItem . getBaseItem ( ) . getHeight ( ) ) + " " ) ;
}
}
} else {
bot . getRoomUnit ( ) . setZ ( bot . getRoomUnit ( ) . getCurrentLocation ( ) . getStackHeight ( ) ) ;
}
roomUnits . add ( bot . getRoomUnit ( ) ) ;
}
if ( ! roomUnits . isEmpty ( ) )
{
this . sendComposer ( new RoomUserStatusComposer ( roomUnits , true ) . compose ( ) ) ;
}
}
2018-07-06 15:30:00 +02:00
public void pickupPetsForHabbo ( Habbo habbo )
{
2018-09-28 21:25:00 +02:00
THashSet < Pet > pets = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
synchronized ( this . currentPets )
{
2018-09-12 18:45:00 +02:00
for ( Pet pet : this . currentPets . valueCollection ( ) )
2018-07-06 15:30:00 +02:00
{
if ( pet . getUserId ( ) = = habbo . getHabboInfo ( ) . getId ( ) )
{
2018-09-28 21:25:00 +02:00
pets . add ( pet ) ;
2018-07-06 15:30:00 +02:00
}
}
}
2018-09-12 18:45:00 +02:00
for ( Pet pet : pets )
2018-07-06 15:30:00 +02:00
{
2019-05-12 09:59:01 +02:00
pet . removeFromRoom ( ) ;
Emulator . getThreading ( ) . run ( pet ) ;
2019-03-18 02:22:00 +01:00
habbo . getInventory ( ) . getPetsComponent ( ) . addPet ( pet ) ;
habbo . getClient ( ) . sendResponse ( new AddPetComposer ( pet ) ) ;
2018-07-06 15:30:00 +02:00
this . currentPets . remove ( pet . getId ( ) ) ;
}
}
public void startTrade ( Habbo userOne , Habbo userTwo )
{
RoomTrade trade = new RoomTrade ( userOne , userTwo , this ) ;
synchronized ( this . activeTrades )
{
this . activeTrades . add ( trade ) ;
}
2018-10-07 00:28:00 +02:00
trade . start ( ) ;
2018-07-06 15:30:00 +02:00
}
public void stopTrade ( RoomTrade trade )
{
synchronized ( this . activeTrades )
{
this . activeTrades . remove ( trade ) ;
}
}
public RoomTrade getActiveTradeForHabbo ( Habbo user )
{
synchronized ( this . activeTrades )
{
for ( RoomTrade trade : this . activeTrades )
{
for ( RoomTradeUser habbo : trade . getRoomTradeUsers ( ) )
{
if ( habbo . getHabbo ( ) = = user )
return trade ;
}
}
}
return null ;
}
public synchronized void dispose ( )
{
synchronized ( this . loadLock )
{
if ( this . preventUnloading )
return ;
if ( Emulator . getPluginManager ( ) . fireEvent ( new RoomUnloadingEvent ( this ) ) . isCancelled ( ) )
return ;
if ( this . loaded )
{
if ( ! this . traxManager . disposed ( ) )
{
this . traxManager . dispose ( ) ;
}
try
{
this . roomCycleTask . cancel ( false ) ;
this . scheduledTasks . clear ( ) ;
this . scheduledComposers . clear ( ) ;
this . loaded = false ;
this . tileCache . clear ( ) ;
synchronized ( this . mutedHabbos )
{
this . mutedHabbos . clear ( ) ;
}
2019-05-04 22:41:18 +02:00
for ( InteractionGameTimer timer : this . getRoomSpecialTypes ( ) . getGameTimers ( ) . values ( ) ) {
timer . setRunning ( false ) ;
}
2018-07-06 15:30:00 +02:00
for ( Game game : this . games )
{
game . stop ( ) ;
}
this . games . clear ( ) ;
2019-05-06 06:23:51 +02:00
removeAllPets ( ownerId ) ;
2018-07-06 15:30:00 +02:00
synchronized ( this . roomItems )
{
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
if ( iterator . value ( ) . needsUpdate ( ) )
iterator . value ( ) . run ( ) ;
} catch ( NoSuchElementException e )
{
break ;
}
}
}
if ( this . roomSpecialTypes ! = null )
{
this . roomSpecialTypes . dispose ( ) ;
}
synchronized ( this . roomItems )
{
this . roomItems . clear ( ) ;
}
synchronized ( this . habboQueue )
{
this . habboQueue . clear ( ) ;
}
2018-09-28 21:25:00 +02:00
2018-07-06 15:30:00 +02:00
for ( Habbo habbo : this . currentHabbos . values ( ) )
{
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
this . sendComposer ( new HotelViewComposer ( ) . compose ( ) ) ;
this . currentHabbos . clear ( ) ;
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
botIterator . advance ( ) ;
botIterator . value ( ) . needsUpdate ( true ) ;
Emulator . getThreading ( ) . run ( botIterator . value ( ) ) ;
} catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
}
this . currentBots . clear ( ) ;
this . currentPets . clear ( ) ;
} catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
this . wordQuiz = " " ;
this . yesVotes = 0 ;
this . noVotes = 0 ;
this . updateDatabaseUserCount ( ) ;
this . preLoaded = true ;
this . layout = null ;
}
Emulator . getPluginManager ( ) . fireEvent ( new RoomUnloadedEvent ( this ) ) ;
}
@SuppressWarnings ( " NullableProblems " )
@Override
public int compareTo ( Room o )
{
if ( o . getUserCount ( ) ! = this . getUserCount ( ) )
{
return o . getCurrentHabbos ( ) . size ( ) - this . getCurrentHabbos ( ) . size ( ) ;
}
return this . id - o . id ;
}
@Override
public void serialize ( ServerMessage message )
{
message . appendInt ( this . id ) ;
message . appendString ( this . name ) ;
if ( this . isPublicRoom ( ) )
{
message . appendInt ( 0 ) ;
message . appendString ( " " ) ;
}
else
{
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 ) ;
message . appendInt ( this . tags . split ( " ; " ) . length ) ;
for ( String s : this . tags . split ( " ; " ) )
{
message . appendString ( s ) ;
}
int base = 0 ;
if ( this . getGuildId ( ) > 0 )
{
base = base | 2 ;
}
if ( this . isPromoted ( ) )
{
base = base | 4 ;
}
if ( ! this . isPublicRoom ( ) )
{
base = base | 8 ;
}
2019-04-22 01:42:00 +02:00
2018-07-06 15:30:00 +02:00
2019-03-18 02:22:00 +01:00
message . appendInt ( base ) ;
2018-07-06 15:30:00 +02:00
if ( this . getGuildId ( ) > 0 )
{
Guild g = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . getGuildId ( ) ) ;
if ( g ! = null )
{
message . appendInt ( g . getId ( ) ) ;
message . appendString ( g . getName ( ) ) ;
message . appendString ( g . getBadge ( ) ) ;
}
else
{
message . appendInt ( 0 ) ;
message . appendString ( " " ) ;
message . appendString ( " " ) ;
}
}
if ( this . promoted )
{
message . appendString ( this . promotion . getTitle ( ) ) ;
message . appendString ( this . promotion . getDescription ( ) ) ;
message . appendInt ( ( this . promotion . getEndTimestamp ( ) - Emulator . getIntUnixTimestamp ( ) ) / 60 ) ;
}
}
public static final Comparator SORT_SCORE = new Comparator ( ) {
@Override
public int compare ( Object o1 , Object o2 ) {
if ( ! ( o1 instanceof Room & & o2 instanceof Room ) )
return 0 ;
return ( ( Room ) o2 ) . getScore ( ) - ( ( Room ) o1 ) . getScore ( ) ;
}
} ;
public static final Comparator SORT_ID = new Comparator ( ) {
@Override
public int compare ( Object o1 , Object o2 ) {
if ( ! ( o1 instanceof Room & & o2 instanceof Room ) )
return 0 ;
return ( ( Room ) o2 ) . getId ( ) - ( ( Room ) o1 ) . getId ( ) ;
}
} ;
@Override
public void run ( )
{
long millis = System . currentTimeMillis ( ) ;
synchronized ( this . loadLock )
{
if ( this . loaded )
{
try
{
Emulator . getThreading ( ) . run (
new Runnable ( )
{
@Override
public void run ( )
{
2019-03-18 02:22:00 +01:00
Room . this . cycle ( ) ;
2018-07-06 15:30:00 +02:00
}
} ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
}
this . save ( ) ;
}
public void save ( )
{
if ( this . needsUpdate )
{
2018-09-28 21:25:00 +02:00
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 15:30:00 +02: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 02:22:00 +01:00
StringBuilder moodLightData = new StringBuilder ( ) ;
2018-07-06 15:30:00 +02:00
int id = 1 ;
for ( RoomMoodlightData data : this . moodlightData . valueCollection ( ) )
{
data . setId ( id ) ;
2019-03-18 02:22:00 +01:00
moodLightData . append ( data . toString ( ) ) . append ( " ; " ) ;
2018-07-06 15:30:00 +02:00
id + + ;
}
2019-03-18 02:22:00 +01:00
statement . setString ( 14 , moodLightData . toString ( ) ) ;
2018-07-06 15:30:00 +02: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 21:25:00 +02:00
statement . setString ( 39 , this . hideWired ? " 1 " : " 0 " ) ;
statement . setInt ( 40 , this . id ) ;
2018-07-06 15:30:00 +02:00
statement . executeUpdate ( ) ;
this . needsUpdate = false ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}
private void updateDatabaseUserCount ( )
{
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " UPDATE rooms SET users = ? WHERE id = ? LIMIT 1 " ) )
{
statement . setInt ( 1 , this . currentHabbos . size ( ) ) ;
statement . setInt ( 2 , this . id ) ;
statement . executeUpdate ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
private void cycle ( )
{
2019-03-18 02:22:00 +01:00
this . cycleTimestamp = System . currentTimeMillis ( ) ;
2018-07-06 15:30:00 +02:00
final boolean [ ] foundRightHolder = { false } ;
2019-03-18 02:22:00 +01:00
boolean loaded ;
2018-07-06 15:30:00 +02:00
synchronized ( this . loadLock )
{
loaded = this . loaded ;
}
2018-11-17 14:28:00 +01:00
this . tileCache . clear ( ) ;
2018-07-06 15:30:00 +02:00
if ( loaded )
{
if ( ! this . scheduledTasks . isEmpty ( ) )
{
ConcurrentSet < Runnable > tasks = this . scheduledTasks ;
this . scheduledTasks = new ConcurrentSet < > ( ) ;
for ( Runnable runnable : tasks )
{
Emulator . getThreading ( ) . run ( runnable ) ;
}
}
2018-09-28 21:25:00 +02:00
for ( ICycleable task : this . roomSpecialTypes . getCycleTasks ( ) )
{
task . cycle ( this ) ;
}
2018-07-06 15:30:00 +02:00
if ( ! this . currentHabbos . isEmpty ( ) )
{
this . idleCycles = 0 ;
2018-09-28 21:25:00 +02:00
THashSet < RoomUnit > updatedUnit = new THashSet < > ( ) ;
ArrayList < Habbo > toKick = new ArrayList < > ( ) ;
2018-07-06 15:30:00 +02:00
final Room room = this ;
final long millis = System . currentTimeMillis ( ) ;
for ( Habbo habbo : this . currentHabbos . values ( ) )
{
if ( ! foundRightHolder [ 0 ] )
{
foundRightHolder [ 0 ] = habbo . getRoomUnit ( ) . getRightsLevel ( ) ! = RoomRightLevels . NONE ;
}
if ( habbo . getRoomUnit ( ) . getHandItem ( ) > 0 & & millis - habbo . getRoomUnit ( ) . getHandItemTimestamp ( ) > ( Room . HAND_ITEM_TIME * 1000 ) )
{
2019-03-18 02:22:00 +01:00
this . giveHandItem ( habbo , 0 ) ;
}
if ( habbo . getRoomUnit ( ) . getEffectId ( ) > 0 & & millis / 1000 > habbo . getRoomUnit ( ) . getEffectEndTimestamp ( ) )
{
this . giveEffect ( habbo , 0 , - 1 ) ;
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
if ( habbo . getRoomUnit ( ) . isKicked )
{
habbo . getRoomUnit ( ) . kickCount + + ;
if ( habbo . getRoomUnit ( ) . kickCount > = 5 )
{
this . scheduledTasks . add ( new Runnable ( )
{
@Override
public void run ( )
{
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , room ) ;
}
} ) ;
continue ;
}
}
2018-07-06 15:30:00 +02:00
if ( Emulator . getConfig ( ) . getBoolean ( " hotel.rooms.auto.idle " ) )
{
if ( ! habbo . getRoomUnit ( ) . isIdle ( ) )
{
habbo . getRoomUnit ( ) . increaseIdleTimer ( ) ;
if ( habbo . getRoomUnit ( ) . isIdle ( ) )
{
2019-03-18 02:22:00 +01:00
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2018-07-06 15:30:00 +02:00
}
}
else
{
habbo . getRoomUnit ( ) . increaseIdleTimer ( ) ;
2019-03-18 02:22:00 +01:00
if ( ! this . isOwner ( habbo ) & & habbo . getRoomUnit ( ) . getIdleTimer ( ) > = Room . IDLE_CYCLES_KICK )
2018-07-06 15:30:00 +02:00
{
UserExitRoomEvent event = new UserExitRoomEvent ( habbo , UserExitRoomEvent . UserExitRoomReason . KICKED_IDLE ) ;
Emulator . getPluginManager ( ) . fireEvent ( event ) ;
if ( ! event . isCancelled ( ) )
{
toKick . add ( habbo ) ;
}
}
}
}
if ( habbo . getHabboStats ( ) . mutedBubbleTracker & & habbo . getHabboStats ( ) . allowTalk ( ) )
{
habbo . getHabboStats ( ) . mutedBubbleTracker = false ;
this . sendComposer ( new RoomUserIgnoredComposer ( habbo , RoomUserIgnoredComposer . UNIGNORED ) . compose ( ) ) ;
}
if ( ! habbo . hasPermission ( " acc_chat_no_flood " ) & & habbo . getHabboStats ( ) . chatCounter > 0 )
{
//if (habbo.getRoomUnit().talkTimeOut == 0 || currentTimestamp - habbo.getRoomUnit().talkTimeOut < 0)
{
habbo . getHabboStats ( ) . chatCounter - - ;
if ( habbo . getHabboStats ( ) . chatCounter > 3 & & ! this . hasRights ( habbo ) )
{
2019-03-18 02:22:00 +01:00
if ( this . chatProtection = = 0 )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
this . floodMuteHabbo ( habbo , 30 ) ;
2018-07-06 15:30:00 +02:00
}
2019-03-18 02:22:00 +01:00
else if ( this . chatProtection = = 1 & & habbo . getHabboStats ( ) . chatCounter > 4 )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
this . floodMuteHabbo ( habbo , 30 ) ;
2018-07-06 15:30:00 +02:00
}
2019-03-18 02:22:00 +01:00
else if ( this . chatProtection = = 2 & & habbo . getHabboStats ( ) . chatCounter > 5 )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
this . floodMuteHabbo ( habbo , 30 ) ;
2018-07-06 15:30:00 +02:00
}
}
}
}
else
{
habbo . getHabboStats ( ) . chatCounter = 0 ;
}
2019-03-18 02:22:00 +01:00
if ( this . cycleRoomUnit ( habbo . getRoomUnit ( ) , RoomUnitType . USER ) )
2018-07-06 15:30:00 +02:00
{
2018-09-12 18:45:00 +02:00
updatedUnit . add ( habbo . getRoomUnit ( ) ) ;
2018-07-06 15:30:00 +02:00
}
}
if ( ! toKick . isEmpty ( ) )
{
for ( Habbo habbo : toKick )
{
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
}
if ( ! this . currentBots . isEmpty ( ) )
{
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
final Bot bot ;
try
{
botIterator . advance ( ) ;
bot = botIterator . value ( ) ;
}
catch ( Exception e )
{
break ;
}
if ( ! this . allowBotsWalk & & bot . getRoomUnit ( ) . isWalking ( ) )
{
bot . getRoomUnit ( ) . stopWalking ( ) ;
updatedUnit . add ( bot . getRoomUnit ( ) ) ;
continue ;
}
2019-04-22 01:42:00 +02:00
botIterator . value ( ) . cycle ( this . allowBotsWalk ) ;
if ( this . cycleRoomUnit ( bot . getRoomUnit ( ) , RoomUnitType . BOT ) )
{
updatedUnit . add ( bot . getRoomUnit ( ) ) ;
}
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
}
}
if ( ! this . currentPets . isEmpty ( ) )
{
if ( this . allowBotsWalk )
{
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; )
{
try
{
petIterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
Pet pet = petIterator . value ( ) ;
if ( this . cycleRoomUnit ( pet . getRoomUnit ( ) , RoomUnitType . PET ) )
{
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
}
pet . cycle ( ) ;
if ( pet . packetUpdate )
{
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
pet . packetUpdate = false ;
}
if ( pet . getRoomUnit ( ) . isWalking ( ) & & pet . getRoomUnit ( ) . getPath ( ) . size ( ) = = 1 & & pet . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . GESTURE ) )
{
pet . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . GESTURE ) ;
updatedUnit . add ( pet . getRoomUnit ( ) ) ;
}
}
}
}
if ( this . rollerSpeed ! = - 1 & & this . rollerCycle > = this . rollerSpeed )
{
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-13 04:09:16 +02:00
this . roomSpecialTypes . getRollers ( ) . forEachValue ( roller - > {
2019-05-04 03:25:43 +02:00
2019-05-13 04:09:16 +02:00
HabboItem newRoller = null ;
2019-04-22 01:42:00 +02:00
2019-05-13 05:11:27 +02:00
RoomTile rollerTile = this . getLayout ( ) . getTile ( roller . getX ( ) , roller . getY ( ) ) ;
if ( rollerTile = = null )
return true ;
2019-05-13 04:09:16 +02:00
THashSet < HabboItem > itemsOnRoller = new THashSet < > ( ) ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:31:21 +02:00
for ( HabboItem item : getItemsAt ( rollerTile ) )
{
if ( item . getZ ( ) > = roller . getZ ( ) + Item . getCurrentHeight ( roller ) ) {
itemsOnRoller . add ( item ) ;
}
}
// itemsOnRoller.addAll(this.getItemsAt(rollerTile));
2019-05-13 04:09:16 +02:00
itemsOnRoller . remove ( roller ) ;
2019-04-22 01:42:00 +02:00
2019-05-13 05:11:27 +02:00
if ( ! rollerTile . hasUnits ( ) & & itemsOnRoller . isEmpty ( ) )
2019-05-13 04:09:16 +02:00
return true ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
RoomTile tileInFront = Room . this . layout . getTileInFront ( Room . this . layout . getTile ( roller . getX ( ) , roller . getY ( ) ) , roller . getRotation ( ) ) ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( tileInFront = = null )
return true ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( ! Room . this . layout . tileExists ( tileInFront . x , tileInFront . y ) )
return true ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( tileInFront . state = = RoomTileState . INVALID )
return true ;
2019-05-04 03:25:43 +02:00
2019-05-13 04:09:16 +02:00
if ( ! tileInFront . getAllowStack ( ) & & ! ( tileInFront . isWalkable ( ) | | tileInFront . state = = RoomTileState . SIT | | tileInFront . state = = RoomTileState . LAY ) )
return true ;
2019-05-04 03:25:43 +02:00
2019-05-13 05:11:27 +02:00
if ( tileInFront . hasUnits ( ) )
2019-05-13 04:09:16 +02:00
return true ;
2019-05-12 17:03:40 +02:00
2019-05-13 04:09:16 +02:00
THashSet < HabboItem > itemsNewTile = new THashSet < > ( ) ;
itemsNewTile . addAll ( getItemsAt ( tileInFront ) ) ;
itemsNewTile . removeAll ( itemsOnRoller ) ;
2019-05-13 03:36:53 +02:00
2019-05-13 04:09:16 +02:00
List < HabboItem > toRemove = new ArrayList < > ( ) ;
for ( HabboItem item : itemsOnRoller )
{
if ( item . getX ( ) ! = roller . getX ( ) | | item . getY ( ) ! = roller . getY ( ) | | rollerFurniIds . contains ( item . getId ( ) ) )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
toRemove . add ( item ) ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
}
itemsOnRoller . removeAll ( toRemove ) ;
HabboItem topItem = Room . this . getTopItemAt ( tileInFront . x , tileInFront . y ) ;
2019-05-13 03:36:53 +02:00
2019-05-13 04:09:16 +02:00
boolean allowUsers = true ;
boolean allowFurniture = true ;
boolean stackContainsRoller = false ;
for ( HabboItem item : itemsNewTile )
{
if ( ! ( item . getBaseItem ( ) . allowWalk ( ) | | item . getBaseItem ( ) . allowSit ( ) ) & & ! ( item instanceof InteractionGate & & item . getExtradata ( ) . equals ( " 1 " ) ) )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
allowUsers = false ;
2019-05-13 03:36:53 +02:00
}
2019-05-13 04:09:16 +02:00
if ( item instanceof InteractionRoller )
2019-05-13 03:36:53 +02:00
{
2019-05-13 04:09:16 +02:00
newRoller = item ;
stackContainsRoller = true ;
2019-05-13 03:36:53 +02:00
2019-05-13 04:09:16 +02:00
if ( ( item . getZ ( ) ! = roller . getZ ( ) | | ( itemsNewTile . size ( ) > 1 & & item ! = topItem ) ) & & ! InteractionRoller . NO_RULES )
2019-05-13 03:36:53 +02:00
{
2019-05-13 04:09:16 +02:00
allowUsers = false ;
2019-04-22 01:42:00 +02:00
allowFurniture = false ;
2019-05-13 04:09:16 +02:00
continue ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
break ;
} else
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
allowFurniture = false ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
}
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( allowFurniture )
{
allowFurniture = tileInFront . getAllowStack ( ) ;
}
double zOffset = 0 ;
if ( newRoller ! = null )
{
if ( ( ! itemsNewTile . isEmpty ( ) & & ( itemsNewTile . size ( ) > 1 ) ) & & ! InteractionRoller . NO_RULES )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
return true ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
}
else
{
zOffset = - Item . getCurrentHeight ( roller ) + tileInFront . getStackHeight ( ) - rollerTile . z ;
}
if ( allowUsers )
{
Event roomUserRolledEvent = null ;
if ( Emulator . getPluginManager ( ) . isRegistered ( UserRolledEvent . class , true ) )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
roomUserRolledEvent = new UserRolledEvent ( null , null , null ) ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 05:11:27 +02:00
ArrayList < RoomUnit > unitsOnTile = new ArrayList < RoomUnit > ( rollerTile . getUnits ( ) ) ;
2019-05-12 17:03:40 +02:00
2019-05-13 05:11:27 +02:00
for ( RoomUnit unit : rollerTile . getUnits ( ) ) {
if ( unit . getRoomUnitType ( ) = = RoomUnitType . PET ) {
Pet pet = this . getPet ( unit ) ;
if ( pet instanceof RideablePet & & ( ( RideablePet ) pet ) . getRider ( ) ! = null ) {
unitsOnTile . remove ( unit ) ;
}
}
}
2019-05-16 13:41:14 +02:00
HabboItem nextTileChair = this . getLowestChair ( tileInFront ) ;
2019-05-13 05:11:27 +02:00
for ( RoomUnit unit : unitsOnTile ) {
if ( rolledUnitIds . contains ( unit . getId ( ) ) ) continue ;
2019-05-13 04:09:16 +02:00
if ( stackContainsRoller & & ! allowFurniture & & ! ( topItem ! = null & & topItem . isWalkable ( ) ) )
continue ;
2018-07-06 15:30:00 +02:00
2019-05-13 05:11:27 +02:00
if ( unit . hasStatus ( RoomUnitStatus . MOVE ) )
continue ;
2018-07-06 15:30:00 +02:00
2019-05-13 05:11:27 +02:00
RoomTile tile = tileInFront . copy ( ) ;
tile . setStackHeight ( unit . getZ ( ) + zOffset ) ;
2018-09-12 18:45:00 +02:00
2019-05-13 05:11:27 +02:00
if ( roomUserRolledEvent ! = null & & unit . getRoomUnitType ( ) = = RoomUnitType . USER )
{
roomUserRolledEvent = new UserRolledEvent ( getHabbo ( unit ) , roller , tile ) ;
Emulator . getPluginManager ( ) . fireEvent ( roomUserRolledEvent ) ;
2018-07-06 15:30:00 +02:00
2019-05-13 05:11:27 +02:00
if ( roomUserRolledEvent . isCancelled ( ) )
continue ;
}
2018-09-28 21:25:00 +02:00
2019-05-13 05:11:27 +02:00
// horse riding
boolean isRiding = false ;
if ( unit . getRoomUnitType ( ) = = RoomUnitType . USER ) {
Habbo rollingHabbo = this . getHabbo ( unit ) ;
2019-05-17 08:33:30 +02:00
if ( rollingHabbo ! = null & & rollingHabbo . getHabboInfo ( ) ! = null ) {
RideablePet riding = rollingHabbo . getHabboInfo ( ) . getRiding ( ) ;
if ( riding ! = null ) {
RoomUnit ridingUnit = riding . getRoomUnit ( ) ;
tile . setStackHeight ( ridingUnit . getZ ( ) + zOffset ) ;
rolledUnitIds . add ( ridingUnit . getId ( ) ) ;
updatedUnit . remove ( ridingUnit ) ;
messages . add ( new RoomUnitOnRollerComposer ( ridingUnit , roller , ridingUnit . getCurrentLocation ( ) , ridingUnit . getZ ( ) , tile , tile . getStackHeight ( ) + ( nextTileChair ! = null ? - 1 : 0 ) , room ) ) ;
isRiding = true ;
}
2019-05-13 04:09:16 +02:00
}
}
2019-05-12 17:03:40 +02:00
2019-05-13 05:11:27 +02:00
rolledUnitIds . add ( unit . getId ( ) ) ;
updatedUnit . remove ( unit ) ;
2019-05-16 13:41:14 +02:00
messages . add ( new RoomUnitOnRollerComposer ( unit , roller , unit . getCurrentLocation ( ) , unit . getZ ( ) + ( isRiding ? 1 : 0 ) , tile , tile . getStackHeight ( ) + ( isRiding ? 1 : 0 ) + ( nextTileChair ! = null ? - 1 : 0 ) , room ) ) ;
2019-05-12 17:03:40 +02:00
2019-05-13 05:11:27 +02:00
if ( itemsOnRoller . isEmpty ( ) )
2019-05-13 04:09:16 +02:00
{
2019-05-13 05:11:27 +02:00
HabboItem item = room . getTopItemAt ( tileInFront . x , tileInFront . y ) ;
2019-05-13 03:36:53 +02:00
2019-05-13 05:11:27 +02:00
if ( item ! = null & & itemsNewTile . contains ( item ) )
2019-05-13 04:09:16 +02:00
{
2019-05-16 11:27:06 +02:00
Emulator . getThreading ( ) . run ( new Runnable ( ) {
@Override
public void run ( ) {
if ( unit . getGoal ( ) = = rollerTile )
{
try
{
item . onWalkOn ( unit , room , null ) ;
} catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
}
} , 500 ) ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
}
2019-04-22 01:42:00 +02:00
2019-05-13 05:11:27 +02:00
if ( unit . hasStatus ( RoomUnitStatus . SIT ) ) {
unit . sitUpdate = true ;
}
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
}
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( ! messages . isEmpty ( ) )
{
for ( MessageComposer message : messages )
2019-03-18 02:22:00 +01:00
{
2019-05-13 04:09:16 +02:00
room . sendComposer ( message . compose ( ) ) ;
2019-03-18 02:22:00 +01:00
}
2019-05-13 04:09:16 +02:00
messages . clear ( ) ;
}
2018-09-28 21:25:00 +02:00
2019-05-13 04:09:16 +02:00
if ( allowFurniture | | ! stackContainsRoller | | InteractionRoller . NO_RULES )
{
Event furnitureRolledEvent = null ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureRolledEvent . class , true ) )
{
furnitureRolledEvent = new FurnitureRolledEvent ( null , null , null ) ;
}
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( newRoller = = null | | topItem = = newRoller )
{
List < HabboItem > sortedItems = new ArrayList < > ( itemsOnRoller ) ;
sortedItems . sort ( new Comparator < HabboItem > ( )
2019-05-12 17:03:40 +02:00
{
2019-05-13 04:09:16 +02:00
@Override
public int compare ( HabboItem o1 , HabboItem o2 )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
return o1 . getZ ( ) > o2 . getZ ( ) ? - 1 : 1 ;
}
} ) ;
2019-05-13 03:36:53 +02:00
2019-05-13 04:09:16 +02:00
for ( HabboItem item : sortedItems )
{
if ( item . getX ( ) = = roller . getX ( ) & & item . getY ( ) = = roller . getY ( ) & & zOffset < = 0 )
2019-05-13 03:36:53 +02:00
{
2019-05-13 04:09:16 +02:00
if ( item ! = roller )
2019-05-13 03:36:53 +02:00
{
2019-05-13 04:09:16 +02:00
if ( furnitureRolledEvent ! = null )
2019-04-22 01:42:00 +02:00
{
2019-05-13 04:09:16 +02:00
furnitureRolledEvent = new FurnitureRolledEvent ( item , roller , tileInFront ) ;
Emulator . getPluginManager ( ) . fireEvent ( furnitureRolledEvent ) ;
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( furnitureRolledEvent . isCancelled ( ) )
continue ;
2019-05-13 03:36:53 +02:00
}
2019-05-13 04:09:16 +02:00
messages . add ( new FloorItemOnRollerComposer ( item , roller , tileInFront , zOffset , room ) ) ;
rollerFurniIds . add ( item . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
}
}
}
2019-03-18 02:22:00 +01:00
}
2019-05-13 04:09:16 +02:00
}
2018-07-06 15:30:00 +02:00
2019-04-22 01:42:00 +02:00
2019-05-13 04:09:16 +02:00
if ( ! messages . isEmpty ( ) )
{
for ( MessageComposer message : messages )
2019-03-18 02:22:00 +01:00
{
2019-05-13 04:09:16 +02:00
room . sendComposer ( message . compose ( ) ) ;
2019-04-22 01:42:00 +02:00
}
2019-05-13 04:09:16 +02:00
messages . clear ( ) ;
2019-05-13 03:36:53 +02:00
}
2019-05-13 04:09:16 +02:00
return true ;
2019-04-22 01:42:00 +02:00
} ) ;
int currentTime = ( int ) ( this . cycleTimestamp / 1000 ) ;
for ( HabboItem pyramid : this . roomSpecialTypes . getItemsOfType ( InteractionPyramid . class ) )
{
if ( pyramid instanceof InteractionPyramid )
{
if ( ( ( InteractionPyramid ) pyramid ) . getNextChange ( ) < currentTime )
{
( ( InteractionPyramid ) pyramid ) . change ( this ) ;
2018-07-06 15:30:00 +02:00
}
}
}
}
2019-04-22 01:42:00 +02:00
else
{
this . rollerCycle + + ;
}
2018-07-06 15:30:00 +02:00
if ( ! updatedUnit . isEmpty ( ) )
{
this . sendComposer ( new RoomUserStatusComposer ( updatedUnit , true ) . compose ( ) ) ;
}
this . traxManager . cycle ( ) ;
}
else
{
if ( this . idleCycles < 60 )
this . idleCycles + + ;
else
this . dispose ( ) ;
}
}
synchronized ( this . habboQueue )
{
if ( ! this . habboQueue . isEmpty ( ) & & ! foundRightHolder [ 0 ] )
{
this . habboQueue . forEachEntry ( new TIntObjectProcedure < Habbo > ( )
{
@Override
public boolean execute ( int a , Habbo b )
{
if ( b . isOnline ( ) )
{
2019-03-18 02:22:00 +01:00
if ( b . getHabboInfo ( ) . getRoomQueueId ( ) = = Room . this . getId ( ) )
2018-07-06 15:30:00 +02:00
{
b . getClient ( ) . sendResponse ( new RoomAccessDeniedComposer ( " " ) ) ;
}
}
return true ;
}
} ) ;
this . habboQueue . clear ( ) ;
}
}
if ( ! this . scheduledComposers . isEmpty ( ) )
{
2019-03-18 02:22:00 +01:00
for ( ServerMessage message : this . scheduledComposers )
2018-07-06 15:30:00 +02:00
{
this . sendComposer ( message ) ;
}
this . scheduledComposers . clear ( ) ;
}
}
2018-09-12 18:45:00 +02:00
private boolean cycleRoomUnit ( RoomUnit unit , RoomUnitType type )
{
2018-09-28 21:25:00 +02:00
boolean update = unit . needsStatusUpdate ( ) ;
2018-09-12 18:45:00 +02:00
if ( unit . hasStatus ( RoomUnitStatus . SIGN ) )
{
2019-03-18 02:22:00 +01:00
this . sendComposer ( new RoomUserStatusComposer ( unit ) . compose ( ) ) ;
2018-09-12 18:45:00 +02:00
unit . removeStatus ( RoomUnitStatus . SIGN ) ;
}
if ( unit . isWalking ( ) & & unit . getPath ( ) ! = null & & ! unit . getPath ( ) . isEmpty ( ) )
{
if ( ! unit . cycle ( this ) )
{
return true ;
}
}
else
{
if ( unit . hasStatus ( RoomUnitStatus . MOVE ) & & ! unit . animateWalk )
{
unit . removeStatus ( RoomUnitStatus . MOVE ) ;
update = true ;
}
if ( ! unit . isWalking ( ) & & ! unit . cmdSit )
{
2019-05-12 09:59:01 +02:00
HabboItem topItem = this . getLowestChair ( this . getLayout ( ) . getTile ( unit . getX ( ) , unit . getY ( ) ) ) ;
2018-09-12 18:45:00 +02:00
if ( topItem = = null | | ! topItem . getBaseItem ( ) . allowSit ( ) )
{
if ( unit . hasStatus ( RoomUnitStatus . SIT ) )
{
unit . removeStatus ( RoomUnitStatus . SIT ) ;
update = true ;
}
}
else
{
if ( ! unit . hasStatus ( RoomUnitStatus . SIT ) | | unit . sitUpdate )
{
2019-03-18 02:22:00 +01:00
this . dance ( unit , DanceType . NONE ) ;
2019-05-12 09:59:01 +02:00
//int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
unit . setStatus ( RoomUnitStatus . SIT , ( Item . getCurrentHeight ( topItem ) * 1 . 0D ) + " " ) ;
2018-10-07 00:28:00 +02:00
unit . setPreviousLocationZ ( topItem . getZ ( ) ) ;
2019-05-15 21:25:29 +02:00
unit . setZ ( topItem . getZ ( ) ) ;
2018-09-12 18:45:00 +02:00
unit . setRotation ( RoomUserRotation . values ( ) [ topItem . getRotation ( ) ] ) ;
unit . sitUpdate = false ;
2018-10-07 00:28:00 +02:00
return true ;
2018-09-12 18:45:00 +02:00
}
}
}
}
if ( ! unit . isWalking ( ) & & ! unit . cmdLay )
{
2019-03-18 02:22:00 +01:00
HabboItem topItem = this . getTopItemAt ( unit . getX ( ) , unit . getY ( ) ) ;
2018-09-12 18:45:00 +02:00
if ( topItem = = null | | ! topItem . getBaseItem ( ) . allowLay ( ) )
{
if ( unit . hasStatus ( RoomUnitStatus . LAY ) )
{
unit . removeStatus ( RoomUnitStatus . LAY ) ;
update = true ;
}
}
else
{
if ( ! unit . hasStatus ( RoomUnitStatus . LAY ) )
{
2019-05-12 09:59:01 +02:00
unit . setStatus ( RoomUnitStatus . LAY , Item . getCurrentHeight ( topItem ) * 1 . 0D + " " ) ;
2018-09-12 18:45:00 +02:00
unit . setRotation ( RoomUserRotation . values ( ) [ topItem . getRotation ( ) ] ) ;
if ( topItem . getRotation ( ) = = 0 | | topItem . getRotation ( ) = = 4 )
{
2019-03-18 02:22:00 +01:00
unit . setLocation ( this . layout . getTile ( unit . getX ( ) , topItem . getY ( ) ) ) ;
2018-09-12 18:45:00 +02:00
//unit.setOldY(topItem.getY());
}
else
{
2019-03-18 02:22:00 +01:00
unit . setLocation ( this . layout . getTile ( topItem . getX ( ) , unit . getY ( ) ) ) ;
2018-09-12 18:45:00 +02:00
//unit.setOldX(topItem.getX());
}
update = true ;
}
}
}
2018-09-28 21:25:00 +02:00
if ( update )
{
unit . statusUpdate ( false ) ;
}
2018-09-12 18:45:00 +02:00
return update ;
}
2018-07-06 15:30:00 +02:00
public int getId ( )
{
return this . id ;
}
public int getOwnerId ( )
{
return this . ownerId ;
}
public void setOwnerId ( int ownerId )
{
this . ownerId = ownerId ;
}
public String getOwnerName ( )
{
return this . ownerName ;
}
public void setOwnerName ( String ownerName )
{
this . ownerName = ownerName ;
}
public String getName ( )
{
return this . name ;
}
public String getDescription ( )
{
return this . description ;
}
public RoomLayout getLayout ( )
{
return this . layout ;
}
public void setLayout ( RoomLayout layout )
{
this . layout = layout ;
}
public boolean hasCustomLayout ( )
{
return this . overrideModel ;
}
public void setHasCustomLayout ( boolean overrideModel )
{
this . overrideModel = overrideModel ;
}
public String getPassword ( )
{
return this . password ;
}
public RoomState getState ( )
{
return this . state ;
}
public int getUsersMax ( )
{
return this . usersMax ;
}
public int getScore ( )
{
return this . score ;
}
public int getCategory ( )
{
return this . category ;
}
public String getFloorPaint ( )
{
return this . floorPaint ;
}
public String getWallPaint ( )
{
return this . wallPaint ;
}
public String getBackgroundPaint ( )
{
return this . backgroundPaint ;
}
public int getWallSize ( )
{
return this . wallSize ;
}
public int getWallHeight ( )
{
return this . wallHeight ;
}
public void setWallHeight ( int wallHeight )
{
this . wallHeight = wallHeight ;
}
public int getFloorSize ( )
{
return this . floorSize ;
}
public String getTags ( )
{
return this . tags ;
}
public int getTradeMode ( )
{
return this . tradeMode ;
}
public boolean moveDiagonally ( )
{
return this . moveDiagonally ;
}
public void moveDiagonally ( boolean moveDiagonally )
{
this . moveDiagonally = moveDiagonally ;
this . layout . moveDiagonally ( this . moveDiagonally ) ;
this . needsUpdate = true ;
}
public int getGuildId ( )
{
return this . guild ;
}
public boolean hasGuild ( )
{
return this . guild ! = 0 ;
}
public void setGuild ( int guild )
{
this . guild = guild ;
}
public String getGuildName ( )
{
if ( this . hasGuild ( ) )
{
Guild guild = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . guild ) ;
if ( guild ! = null )
{
return guild . getName ( ) ;
}
}
return " " ;
}
public boolean isPublicRoom ( )
{
return this . publicRoom ;
}
2018-12-22 11:39:00 +01:00
public void setPublicRoom ( boolean publicRoom )
{
this . publicRoom = publicRoom ;
}
2018-07-06 15:30:00 +02:00
public boolean isStaffPromotedRoom ( )
{
return this . staffPromotedRoom ;
}
public void setStaffPromotedRoom ( boolean staffPromotedRoom )
{
this . staffPromotedRoom = staffPromotedRoom ;
}
public boolean isAllowPets ( )
{
return this . allowPets ;
}
public boolean isAllowPetsEat ( )
{
return this . allowPetsEat ;
}
public boolean isAllowWalkthrough ( )
{
return this . allowWalkthrough ;
}
public boolean isAllowBotsWalk ( )
{
return this . allowBotsWalk ;
}
public boolean isAllowEffects ( )
{
return this . allowEffects ;
}
public void setAllowEffects ( boolean allowEffects )
{
this . allowEffects = allowEffects ;
}
public boolean isHideWall ( )
{
return this . hideWall ;
}
public Color getBackgroundTonerColor ( )
{
Color color = new Color ( 0 , 0 , 0 ) ;
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i > 0 ; i - - )
{
try
{
iterator . advance ( ) ;
HabboItem object = iterator . value ( ) ;
if ( object instanceof InteractionBackgroundToner )
{
String [ ] extraData = object . getExtradata ( ) . split ( " : " ) ;
if ( extraData . length = = 4 )
{
if ( extraData [ 0 ] . equalsIgnoreCase ( " 1 " ) )
{
return Color . getHSBColor ( Integer . valueOf ( extraData [ 1 ] ) , Integer . valueOf ( extraData [ 2 ] ) , Integer . valueOf ( extraData [ 3 ] ) ) ;
}
}
}
}
catch ( Exception e )
{
}
}
return color ;
}
public int getChatMode ( )
{
return this . chatMode ;
}
public int getChatWeight ( )
{
return this . chatWeight ;
}
public int getChatSpeed ( )
{
return this . chatSpeed ;
}
public int getChatDistance ( )
{
return this . chatDistance ;
}
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 void setDescription ( String description )
{
this . description = description ;
if ( this . description . length ( ) > 250 )
{
this . description = this . description . substring ( 0 , 250 ) ;
}
}
public void setPassword ( String password )
{
this . password = password ;
if ( this . password . length ( ) > 20 )
{
this . password = this . password . substring ( 0 , 20 ) ;
}
}
public void setState ( RoomState state )
{
this . state = state ;
}
public void setUsersMax ( int usersMax )
{
this . usersMax = usersMax ;
}
public void setScore ( int score )
{
this . score = score ;
}
public void setCategory ( int category )
{
this . category = category ;
}
public void setFloorPaint ( String floorPaint )
{
this . floorPaint = floorPaint ;
}
public void setWallPaint ( String wallPaint )
{
this . wallPaint = wallPaint ;
}
public void setBackgroundPaint ( String backgroundPaint )
{
this . backgroundPaint = backgroundPaint ;
}
public void setWallSize ( int wallSize )
{
this . wallSize = wallSize ;
}
public void setFloorSize ( int floorSize )
{
this . floorSize = floorSize ;
}
public void setTags ( String tags )
{
this . tags = tags ;
}
public void setTradeMode ( int tradeMode )
{
this . tradeMode = tradeMode ;
}
public void setAllowPets ( boolean allowPets )
{
this . allowPets = allowPets ;
2019-05-06 06:23:51 +02:00
if ( ! allowPets ) {
removeAllPets ( ownerId ) ;
}
}
public void removeAllPets ( ) {
removeAllPets ( - 1 ) ;
}
/ * *
* Removes all pets from the room except if the owner id is excludeUserId
* @param excludeUserId Habbo id to keep pets
* /
public void removeAllPets ( int excludeUserId ) {
ArrayList < Pet > removedPets = new ArrayList < > ( ) ;
synchronized ( this . currentPets ) {
for ( Pet pet : this . currentPets . valueCollection ( ) ) {
try {
if ( pet . getUserId ( ) ! = excludeUserId ) {
2019-05-12 09:59:01 +02:00
pet . removeFromRoom ( ) ;
2019-05-06 06:23:51 +02:00
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 ( ) ;
} catch ( NoSuchElementException e ) {
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
}
}
for ( Pet pet : removedPets ) {
this . currentPets . remove ( pet . getId ( ) ) ;
}
2018-07-06 15:30:00 +02:00
}
public void setAllowPetsEat ( boolean allowPetsEat )
{
this . allowPetsEat = allowPetsEat ;
}
public void setAllowWalkthrough ( boolean allowWalkthrough )
{
this . allowWalkthrough = allowWalkthrough ;
}
public void setAllowBotsWalk ( boolean allowBotsWalk )
{
this . allowBotsWalk = allowBotsWalk ;
}
public void setHideWall ( boolean hideWall )
{
this . hideWall = hideWall ;
}
public void setChatMode ( int chatMode )
{
this . chatMode = chatMode ;
}
public void setChatWeight ( int chatWeight )
{
this . chatWeight = chatWeight ;
}
public void setChatSpeed ( int chatSpeed )
{
this . chatSpeed = chatSpeed ;
}
public void setChatDistance ( int chatDistance )
{
this . chatDistance = chatDistance ;
}
public int getChatProtection ( )
{
return this . chatProtection ;
}
public void setChatProtection ( int chatProtection )
{
this . chatProtection = chatProtection ;
}
public int getMuteOption ( )
{
return this . muteOption ;
}
public void setMuteOption ( int muteOption )
{
this . muteOption = muteOption ;
}
public int getKickOption ( )
{
return this . kickOption ;
}
public void setKickOption ( int kickOption )
{
this . kickOption = kickOption ;
}
public int getBanOption ( )
{
return this . banOption ;
}
public void setBanOption ( int banOption )
{
this . banOption = banOption ;
}
public int getPollId ( )
{
return this . pollId ;
}
public int getRollerSpeed ( )
{
return this . rollerSpeed ;
}
public String [ ] filterAnything ( )
{
2019-03-18 02:22:00 +01:00
return new String [ ] { this . getOwnerName ( ) , this . getGuildName ( ) , this . getDescription ( ) , this . getPromotionDesc ( ) } ;
}
public long getCycleTimestamp ( )
{
return this . cycleTimestamp ;
2018-07-06 15:30:00 +02:00
}
public boolean isPromoted ( )
{
this . promoted = this . promotion ! = null & & this . promotion . getEndTimestamp ( ) > Emulator . getIntUnixTimestamp ( ) ;
this . needsUpdate = true ;
return this . promoted ;
}
public RoomPromotion getPromotion ( )
{
return this . promotion ;
}
public String getPromotionDesc ( )
{
if ( this . promotion ! = null )
{
return this . promotion . getDescription ( ) ;
}
return " " ;
}
public void createPromotion ( String title , String description )
{
this . promoted = true ;
if ( this . promotion = = null )
{
this . promotion = new RoomPromotion ( this , title , description , Emulator . getIntUnixTimestamp ( ) + ( 120 * 60 ) ) ;
}
else
{
this . promotion . setTitle ( title ) ;
this . promotion . setDescription ( description ) ;
this . promotion . setEndTimestamp ( Emulator . getIntUnixTimestamp ( ) + ( 120 * 60 ) ) ;
}
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO room_promotions (room_id, title, description, end_timestamp) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
statement . setString ( 2 , title ) ;
statement . setString ( 3 , description ) ;
statement . setInt ( 4 , this . promotion . getEndTimestamp ( ) ) ;
statement . setString ( 5 , this . promotion . getTitle ( ) ) ;
statement . setString ( 6 , this . promotion . getDescription ( ) ) ;
statement . setInt ( 7 , this . promotion . getEndTimestamp ( ) ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
this . needsUpdate = true ;
}
public void setRollerSpeed ( int rollerSpeed )
{
this . rollerSpeed = rollerSpeed ;
this . rollerCycle = 0 ;
this . needsUpdate = true ;
}
public void setPollId ( int pollId )
{
this . pollId = pollId ;
}
public boolean addGame ( Game game )
{
synchronized ( this . games )
{
return this . games . add ( game ) ;
}
}
public boolean deleteGame ( Game game )
{
game . stop ( ) ;
synchronized ( this . games )
{
return this . games . remove ( game ) ;
}
}
public Game getGame ( Class < ? extends Game > gameType )
{
synchronized ( this . games )
{
for ( Game game : this . games )
{
if ( gameType . isInstance ( game ) )
{
return game ;
}
}
}
return null ;
}
public int getUserCount ( )
{
2019-05-04 03:25:43 +02:00
return this . currentHabbos . size ( ) ;
2018-07-06 15:30:00 +02:00
}
public ConcurrentHashMap < Integer , Habbo > getCurrentHabbos ( )
{
return this . currentHabbos ;
}
public Collection < Habbo > getHabbos ( )
{
return this . currentHabbos . values ( ) ;
}
public TIntObjectMap < Habbo > getHabboQueue ( )
{
return this . habboQueue ;
}
public TIntObjectMap < String > getFurniOwnerNames ( )
{
return this . furniOwnerNames ;
}
public String getFurniOwnerName ( int userId )
{
return this . furniOwnerNames . get ( userId ) ;
}
public TIntIntMap getFurniOwnerCount ( )
{
return this . furniOwnerCount ;
}
public TIntObjectMap < RoomMoodlightData > getMoodlightData ( )
{
return this . moodlightData ;
}
public int getLastTimerReset ( )
{
return this . lastTimerReset ;
}
public void setLastTimerReset ( int lastTimerReset )
{
this . lastTimerReset = lastTimerReset ;
}
public void addToQueue ( Habbo habbo )
{
synchronized ( this . habboQueue )
{
this . habboQueue . put ( habbo . getHabboInfo ( ) . getId ( ) , habbo ) ;
}
}
public boolean removeFromQueue ( Habbo habbo )
{
try
{
this . sendComposer ( new HideDoorbellComposer ( habbo . getHabboInfo ( ) . getUsername ( ) ) . compose ( ) ) ;
synchronized ( this . habboQueue )
{
return this . habboQueue . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ! = null ;
}
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
return true ;
}
public TIntObjectMap < Bot > getCurrentBots ( )
{
return this . currentBots ;
}
2018-09-12 18:45:00 +02:00
public TIntObjectMap < Pet > getCurrentPets ( )
2018-07-06 15:30:00 +02:00
{
return this . currentPets ;
}
public THashSet < String > getWordFilterWords ( )
{
return this . wordFilterWords ;
}
public RoomSpecialTypes getRoomSpecialTypes ( )
{
return this . roomSpecialTypes ;
}
public boolean isPreLoaded ( )
{
return this . preLoaded ;
}
public boolean isLoaded ( )
{
return this . loaded ;
}
public void setNeedsUpdate ( boolean needsUpdate )
{
this . needsUpdate = needsUpdate ;
}
public TIntArrayList getRights ( )
{
2019-03-18 02:22:00 +01:00
return this . rights ;
2018-07-06 15:30:00 +02:00
}
public boolean isMuted ( )
{
return this . muted ;
}
public void setMuted ( boolean muted )
{
this . muted = muted ;
}
public TraxManager getTraxManager ( )
{
return this . traxManager ;
}
public void addHabboItem ( HabboItem item )
{
if ( item = = null )
return ;
2019-03-18 02:22:00 +01:00
synchronized ( this . roomItems )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
try
{
this . roomItems . put ( item . getId ( ) , item ) ;
} catch ( Exception e )
{
2018-07-06 15:30:00 +02:00
2019-03-18 02:22:00 +01:00
}
2018-07-06 15:30:00 +02:00
}
synchronized ( this . furniOwnerCount )
{
this . furniOwnerCount . put ( item . getUserId ( ) , this . furniOwnerCount . get ( item . getUserId ( ) ) + 1 ) ;
}
synchronized ( this . furniOwnerNames )
{
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) )
{
HabboInfo habbo = HabboManager . getOfflineHabboInfo ( item . getUserId ( ) ) ;
if ( habbo ! = null )
{
this . furniOwnerNames . put ( item . getUserId ( ) , habbo . getUsername ( ) ) ;
}
else
{
Emulator . getLogging ( ) . logDebugLine ( " Failed to find username for item (ID: " + item . getId ( ) + " , UserID: " + item . getUserId ( ) + " ) " ) ;
}
}
}
//TODO: Move this list
synchronized ( this . roomSpecialTypes )
{
if ( item instanceof ICycleable )
{
this . roomSpecialTypes . addCycleTask ( ( ICycleable ) item ) ;
}
if ( item instanceof InteractionWiredTrigger )
{
this . roomSpecialTypes . addTrigger ( ( InteractionWiredTrigger ) item ) ;
} else if ( item instanceof InteractionWiredEffect )
{
this . roomSpecialTypes . addEffect ( ( InteractionWiredEffect ) item ) ;
} else if ( item instanceof InteractionWiredCondition )
{
this . roomSpecialTypes . addCondition ( ( InteractionWiredCondition ) item ) ;
} else if ( item instanceof InteractionWiredExtra )
{
this . roomSpecialTypes . addExtra ( ( InteractionWiredExtra ) item ) ;
} else if ( item instanceof InteractionBattleBanzaiTeleporter )
{
this . roomSpecialTypes . addBanzaiTeleporter ( ( InteractionBattleBanzaiTeleporter ) item ) ;
} else if ( item instanceof InteractionRoller )
{
this . roomSpecialTypes . addRoller ( ( InteractionRoller ) item ) ;
} else if ( item instanceof InteractionGameScoreboard )
{
this . roomSpecialTypes . addGameScoreboard ( ( InteractionGameScoreboard ) item ) ;
} else if ( item instanceof InteractionGameGate )
{
this . roomSpecialTypes . addGameGate ( ( InteractionGameGate ) item ) ;
} else if ( item instanceof InteractionGameTimer )
{
this . roomSpecialTypes . addGameTimer ( ( InteractionGameTimer ) item ) ;
} else if ( item instanceof InteractionFreezeExitTile )
{
this . roomSpecialTypes . addFreezeExitTile ( ( InteractionFreezeExitTile ) item ) ;
} else if ( item instanceof InteractionNest )
{
this . roomSpecialTypes . addNest ( ( InteractionNest ) item ) ;
} else if ( item instanceof InteractionPetDrink )
{
this . roomSpecialTypes . addPetDrink ( ( InteractionPetDrink ) item ) ;
} else if ( item instanceof InteractionPetFood )
{
this . roomSpecialTypes . addPetFood ( ( InteractionPetFood ) item ) ;
} else if ( item instanceof InteractionMoodLight )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionPyramid )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionMusicDisc )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionBattleBanzaiSphere )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionTalkingFurniture )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionWater )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionWaterItem )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionMuteArea )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionTagPole )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionTagField )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionJukeBox )
{
this . roomSpecialTypes . addUndefined ( item ) ;
} else if ( item instanceof InteractionPetBreedingNest )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
else if ( item instanceof InteractionBlackHole )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
else if ( item instanceof InteractionWiredHighscore )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
else if ( item instanceof InteractionStickyPole )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
2018-09-28 21:25:00 +02:00
else if ( item instanceof WiredBlob )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
else if ( item instanceof InteractionTent )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
2018-12-22 11:39:00 +01:00
else if ( item instanceof InteractionSnowboardSlope )
{
this . roomSpecialTypes . addUndefined ( item ) ;
}
2018-07-06 15:30:00 +02:00
}
}
public HabboItem getHabboItem ( int id )
{
HabboItem item ;
synchronized ( this . roomItems )
{
item = this . roomItems . get ( id ) ;
}
if ( item = = null )
item = this . roomSpecialTypes . getBanzaiTeleporter ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getTrigger ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getEffect ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getCondition ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getGameGate ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getGameScorebord ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getGameTimer ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getFreezeExitTiles ( ) . get ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getRoller ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getNest ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getPetDrink ( id ) ;
if ( item = = null )
item = this . roomSpecialTypes . getPetFood ( id ) ;
return item ;
}
void removeHabboItem ( int id )
{
this . removeHabboItem ( this . getHabboItem ( id ) ) ;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public void removeHabboItem ( HabboItem item )
{
if ( item ! = null )
{
HabboItem i ;
synchronized ( this . roomItems )
{
i = this . roomItems . remove ( item . getId ( ) ) ;
}
if ( i ! = null )
{
synchronized ( this . furniOwnerCount )
{
synchronized ( this . furniOwnerNames )
{
int count = this . furniOwnerCount . get ( i . getUserId ( ) ) ;
if ( count > 1 )
this . furniOwnerCount . put ( i . getUserId ( ) , count - 1 ) ;
else
{
this . furniOwnerCount . remove ( i . getUserId ( ) ) ;
this . furniOwnerNames . remove ( i . getUserId ( ) ) ;
}
}
}
if ( item instanceof ICycleable )
{
this . roomSpecialTypes . removeCycleTask ( ( ICycleable ) item ) ;
}
if ( item instanceof InteractionBattleBanzaiTeleporter )
{
this . roomSpecialTypes . removeBanzaiTeleporter ( ( InteractionBattleBanzaiTeleporter ) item ) ;
}
else if ( item instanceof InteractionWiredTrigger )
{
this . roomSpecialTypes . removeTrigger ( ( InteractionWiredTrigger ) item ) ;
}
else if ( item instanceof InteractionWiredEffect )
{
this . roomSpecialTypes . removeEffect ( ( InteractionWiredEffect ) item ) ;
}
else if ( item instanceof InteractionWiredCondition )
{
this . roomSpecialTypes . removeCondition ( ( InteractionWiredCondition ) item ) ;
}
else if ( item instanceof InteractionWiredExtra )
{
this . roomSpecialTypes . removeExtra ( ( InteractionWiredExtra ) item ) ;
}
else if ( item instanceof InteractionRoller )
{
this . roomSpecialTypes . removeRoller ( ( InteractionRoller ) item ) ;
}
else if ( item instanceof InteractionGameScoreboard )
{
this . roomSpecialTypes . removeScoreboard ( ( InteractionGameScoreboard ) item ) ;
}
else if ( item instanceof InteractionGameGate )
{
this . roomSpecialTypes . removeGameGate ( ( InteractionGameGate ) item ) ;
}
else if ( item instanceof InteractionGameTimer )
{
this . roomSpecialTypes . removeGameTimer ( ( InteractionGameTimer ) item ) ;
}
else if ( item instanceof InteractionFreezeExitTile )
{
this . roomSpecialTypes . removeFreezeExitTile ( ( InteractionFreezeExitTile ) item ) ;
}
else if ( item instanceof InteractionNest )
{
this . roomSpecialTypes . removeNest ( ( InteractionNest ) item ) ;
}
else if ( item instanceof InteractionPetDrink )
{
this . roomSpecialTypes . removePetDrink ( ( InteractionPetDrink ) item ) ;
}
else if ( item instanceof InteractionPetFood )
{
this . roomSpecialTypes . removePetFood ( ( InteractionPetFood ) item ) ;
}
else if ( item instanceof InteractionMoodLight )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionPyramid )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionMusicDisc )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionBattleBanzaiSphere )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionTalkingFurniture )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionWaterItem )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionWater )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionMuteArea )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionTagPole )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionTagField )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionJukeBox )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionPetBreedingNest )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionBlackHole )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionWiredHighscore )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionStickyPole )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
2018-09-28 21:25:00 +02:00
else if ( item instanceof WiredBlob )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
else if ( item instanceof InteractionTent )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
2018-12-22 11:39:00 +01:00
else if ( item instanceof InteractionSnowboardSlope )
{
this . roomSpecialTypes . removeUndefined ( item ) ;
}
2018-07-06 15:30:00 +02:00
}
}
}
public THashSet < HabboItem > getFloorItems ( )
{
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
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 ( ) . getType ( ) = = FurnitureType . FLOOR )
items . add ( iterator . value ( ) ) ;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
2019-05-04 03:25:43 +02:00
return items ;
2018-07-06 15:30:00 +02:00
}
public THashSet < HabboItem > getWallItems ( )
{
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
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 ( ) . getType ( ) = = FurnitureType . WALL )
items . add ( iterator . value ( ) ) ;
}
return items ;
}
public void addHabbo ( Habbo habbo )
{
2019-05-04 03:25:43 +02:00
synchronized ( this . roomUnitLock )
{
habbo . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentHabbos . put ( habbo . getHabboInfo ( ) . getId ( ) , habbo ) ;
this . unitCounter + + ;
this . updateDatabaseUserCount ( ) ;
}
2018-07-06 15:30:00 +02:00
}
public void kickHabbo ( Habbo habbo , boolean alert )
{
if ( alert )
{
habbo . getClient ( ) . sendResponse ( new GenericErrorMessagesComposer ( GenericErrorMessagesComposer . KICKED_OUT_OF_THE_ROOM ) ) ;
}
habbo . getRoomUnit ( ) . isKicked = true ;
habbo . getRoomUnit ( ) . setGoalLocation ( this . layout . getDoorTile ( ) ) ;
if ( habbo . getRoomUnit ( ) . getPath ( ) = = null | | habbo . getRoomUnit ( ) . getPath ( ) . size ( ) < = 1 | | this . isPublicRoom ( ) )
{
habbo . getRoomUnit ( ) . setCanWalk ( true ) ;
Emulator . getGameEnvironment ( ) . getRoomManager ( ) . leaveRoom ( habbo , this ) ;
}
}
2019-05-12 09:59:01 +02:00
public void removeHabbo ( Habbo habbo ) {
removeHabbo ( habbo , false ) ;
}
public void removeHabbo ( Habbo habbo , boolean sendRemovePacket )
2018-07-06 15:30:00 +02:00
{
2019-05-12 09:59:01 +02:00
if ( habbo . getRoomUnit ( ) ! = null & & habbo . getRoomUnit ( ) . getCurrentLocation ( ) ! = null ) {
habbo . getRoomUnit ( ) . getCurrentLocation ( ) . removeUnit ( habbo . getRoomUnit ( ) ) ;
}
if ( sendRemovePacket & & habbo . getRoomUnit ( ) ! = null ) {
this . sendComposer ( new RoomUserRemoveComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
}
2019-03-18 02:22:00 +01:00
HabboItem item = this . getTopItemAt ( habbo . getRoomUnit ( ) . getX ( ) , habbo . getRoomUnit ( ) . getY ( ) ) ;
2018-07-06 15:30:00 +02:00
if ( item ! = null )
{
try
{
item . onWalkOff ( habbo . getRoomUnit ( ) , this , new Object [ ] { } ) ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
synchronized ( this . roomUnitLock )
{
this . currentHabbos . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
if ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ! = null )
{
if ( this . getGame ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ) ! = null )
{
this . getGame ( habbo . getHabboInfo ( ) . getCurrentGame ( ) ) . removeHabbo ( habbo ) ;
}
}
RoomTrade trade = this . getActiveTradeForHabbo ( habbo ) ;
if ( trade ! = null )
{
trade . stopTrade ( habbo ) ;
}
2019-05-06 06:23:51 +02:00
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . ownerId )
{
this . pickupPetsForHabbo ( habbo ) ;
}
2018-07-06 15:30:00 +02:00
this . updateDatabaseUserCount ( ) ;
}
public void addBot ( Bot bot )
{
synchronized ( this . roomUnitLock )
{
bot . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentBots . put ( bot . getId ( ) , bot ) ;
this . unitCounter + + ;
}
}
2018-09-12 18:45:00 +02:00
public void addPet ( Pet pet )
2018-07-06 15:30:00 +02:00
{
synchronized ( this . roomUnitLock )
{
pet . getRoomUnit ( ) . setId ( this . unitCounter ) ;
this . currentPets . put ( pet . getId ( ) , pet ) ;
this . unitCounter + + ;
Habbo habbo = this . getHabbo ( pet . getUserId ( ) ) ;
if ( habbo ! = null )
{
this . furniOwnerNames . put ( pet . getUserId ( ) , this . getHabbo ( pet . getUserId ( ) ) . getHabboInfo ( ) . getUsername ( ) ) ;
}
}
}
public Bot getBot ( int botId )
{
return this . currentBots . get ( botId ) ;
}
2018-12-22 11:39:00 +01:00
public Bot getBot ( RoomUnit roomUnit )
{
synchronized ( this . currentBots )
{
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
if ( iterator . value ( ) . getRoomUnit ( ) = = roomUnit )
return iterator . value ( ) ;
}
}
return null ;
}
public Bot getBotByRoomUnitId ( int id )
{
synchronized ( this . currentBots )
{
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
if ( iterator . value ( ) . getRoomUnit ( ) . getId ( ) = = id )
return iterator . value ( ) ;
}
}
return null ;
}
2018-07-06 15:30:00 +02:00
public List < Bot > getBots ( String name )
{
2018-09-28 21:25:00 +02:00
List < Bot > bots = new ArrayList < > ( ) ;
2018-07-06 15:30:00 +02:00
synchronized ( this . currentBots )
{
TIntObjectIterator < Bot > iterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
if ( iterator . value ( ) . getName ( ) . equalsIgnoreCase ( name ) )
bots . add ( iterator . value ( ) ) ;
}
}
return bots ;
}
public boolean hasBotsAt ( final int x , final int y )
{
final boolean [ ] result = { false } ;
synchronized ( this . currentBots )
{
this . currentBots . forEachValue ( new TObjectProcedure < Bot > ( )
{
@Override
public boolean execute ( Bot object )
{
if ( object . getRoomUnit ( ) . getX ( ) = = x & & object . getRoomUnit ( ) . getY ( ) = = y )
{
result [ 0 ] = true ;
return false ;
}
return true ;
}
} ) ;
}
return result [ 0 ] ;
}
2018-09-12 18:45:00 +02:00
public Pet getPet ( int petId )
2018-07-06 15:30:00 +02:00
{
return this . currentPets . get ( petId ) ;
}
2018-09-12 18:45:00 +02:00
public Pet getPet ( RoomUnit roomUnit )
2018-07-06 15:30:00 +02:00
{
2018-09-12 18:45:00 +02:00
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
2018-07-06 15:30:00 +02:00
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; )
{
try
{
petIterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
if ( petIterator . value ( ) . getRoomUnit ( ) = = roomUnit )
return petIterator . value ( ) ;
}
return null ;
}
public boolean removeBot ( Bot bot )
{
synchronized ( this . currentBots )
{
if ( this . currentBots . containsKey ( bot . getId ( ) ) )
{
2019-05-12 09:59:01 +02:00
if ( bot . getRoomUnit ( ) ! = null & & bot . getRoomUnit ( ) . getCurrentLocation ( ) ! = null ) {
bot . getRoomUnit ( ) . getCurrentLocation ( ) . removeUnit ( bot . getRoomUnit ( ) ) ;
}
2018-07-06 15:30:00 +02: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 ;
}
2018-09-12 18:45:00 +02:00
public void placePet ( Pet pet , short x , short y , double z , int rot )
2018-07-06 15:30:00 +02:00
{
synchronized ( this . currentPets )
{
RoomTile tile = this . layout . getTile ( x , y ) ;
if ( tile = = null )
{
tile = this . layout . getDoorTile ( ) ;
}
pet . setRoomUnit ( new RoomUnit ( ) ) ;
pet . setRoom ( this ) ;
2018-10-07 00:28:00 +02:00
pet . getRoomUnit ( ) . setGoalLocation ( tile ) ;
2018-07-06 15:30:00 +02:00
pet . getRoomUnit ( ) . setLocation ( tile ) ;
pet . getRoomUnit ( ) . setRoomUnitType ( RoomUnitType . PET ) ;
pet . getRoomUnit ( ) . setCanWalk ( true ) ;
pet . getRoomUnit ( ) . setPathFinderRoom ( this ) ;
2018-10-07 00:28:00 +02:00
pet . getRoomUnit ( ) . setPreviousLocationZ ( z ) ;
pet . getRoomUnit ( ) . setZ ( z ) ;
2018-07-06 15:30:00 +02:00
if ( pet . getRoomUnit ( ) . getCurrentLocation ( ) = = null )
{
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 ( ) ) ;
}
}
2018-09-12 18:45:00 +02:00
public Pet removePet ( int petId )
2018-07-06 15:30:00 +02:00
{
return this . currentPets . remove ( petId ) ;
}
public boolean hasHabbosAt ( int x , int y )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getRoomUnit ( ) . getX ( ) = = x & & habbo . getRoomUnit ( ) . getY ( ) = = y )
return true ;
}
return false ;
}
public boolean hasPetsAt ( int x , int y )
{
synchronized ( this . currentPets )
{
2018-09-12 18:45:00 +02:00
TIntObjectIterator < Pet > petIterator = this . currentPets . iterator ( ) ;
2018-07-06 15:30:00 +02:00
for ( int i = this . currentPets . size ( ) ; i - - > 0 ; )
{
try
{
petIterator . advance ( ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
if ( petIterator . value ( ) . getRoomUnit ( ) . getX ( ) = = x & & petIterator . value ( ) . getRoomUnit ( ) . getY ( ) = = y )
return true ;
}
}
return false ;
}
2018-12-22 11:39:00 +01:00
public THashSet < Bot > getBotsAt ( RoomTile tile )
{
THashSet < Bot > bots = new THashSet < > ( ) ;
synchronized ( this . currentBots )
{
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
botIterator . advance ( ) ;
if ( botIterator . value ( ) . getRoomUnit ( ) . getCurrentLocation ( ) . equals ( tile ) )
{
bots . add ( botIterator . value ( ) ) ;
}
}
catch ( Exception e )
{
break ;
}
}
}
return bots ;
}
2018-07-06 15:30:00 +02:00
public THashSet < Habbo > getHabbosAt ( short x , short y )
{
2019-03-18 02:22:00 +01:00
return this . getHabbosAt ( this . layout . getTile ( x , y ) ) ;
2018-07-06 15:30:00 +02:00
}
public THashSet < Habbo > getHabbosAt ( RoomTile tile )
{
2018-09-28 21:25:00 +02:00
THashSet < Habbo > habbos = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) . equals ( tile ) )
habbos . add ( habbo ) ;
}
return habbos ;
}
public THashSet < Habbo > getHabbosOnItem ( HabboItem item )
{
2018-09-28 21:25:00 +02:00
THashSet < Habbo > habbos = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02: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 02:22:00 +01:00
habbos . addAll ( this . getHabbosAt ( x , y ) ) ;
2018-07-06 15:30:00 +02:00
}
}
return habbos ;
}
2018-12-22 11:39:00 +01:00
public THashSet < Bot > getBotsOnItem ( HabboItem item )
{
THashSet < Bot > bots = new THashSet < > ( ) ;
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 02:22:00 +01:00
bots . addAll ( this . getBotsAt ( this . getLayout ( ) . getTile ( x , y ) ) ) ;
2018-12-22 11:39:00 +01:00
}
}
return bots ;
}
2018-07-06 15:30:00 +02:00
public void teleportHabboToItem ( Habbo habbo , HabboItem item )
{
2019-05-12 09:59:01 +02:00
this . teleportRoomUnitToLocation ( habbo . getRoomUnit ( ) , item . getX ( ) , item . getY ( ) , item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 15:30:00 +02:00
}
public void teleportHabboToLocation ( Habbo habbo , short x , short y )
{
2019-03-18 02:22:00 +01:00
this . teleportRoomUnitToLocation ( habbo . getRoomUnit ( ) , x , y , 0 . 0 ) ;
2018-07-06 15:30:00 +02:00
}
2019-03-18 02:22:00 +01:00
public void teleportRoomUnitToItem ( RoomUnit roomUnit , HabboItem item )
{
2019-05-12 09:59:01 +02:00
this . teleportRoomUnitToLocation ( roomUnit , item . getX ( ) , item . getY ( ) , item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2019-03-18 02:22:00 +01:00
}
public void teleportRoomUnitToLocation ( RoomUnit roomUnit , short x , short y )
{
this . teleportRoomUnitToLocation ( roomUnit , x , y , 0 . 0 ) ;
}
void teleportRoomUnitToLocation ( RoomUnit roomUnit , short x , short y , double z )
2018-07-06 15:30:00 +02:00
{
if ( this . loaded )
{
RoomTile tile = this . layout . getTile ( x , y ) ;
2019-03-18 02:22:00 +01:00
if ( z < tile . z )
{
z = tile . z ;
}
roomUnit . setLocation ( tile ) ;
roomUnit . setGoalLocation ( tile ) ;
roomUnit . setZ ( z ) ;
roomUnit . setPreviousLocationZ ( z ) ;
this . updateRoomUnit ( roomUnit ) ;
2019-04-22 01:42:00 +02:00
2018-07-06 15:30:00 +02:00
}
}
public void muteHabbo ( Habbo habbo , int minutes )
{
synchronized ( this . mutedHabbos )
{
this . mutedHabbos . put ( habbo . getHabboInfo ( ) . getId ( ) , Emulator . getIntUnixTimestamp ( ) + ( minutes * 60 ) ) ;
}
}
public boolean isMuted ( Habbo habbo )
{
if ( this . isOwner ( habbo ) | | this . hasRights ( habbo ) )
return false ;
if ( this . mutedHabbos . containsKey ( habbo . getHabboInfo ( ) . getId ( ) ) )
{
boolean time = this . mutedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) > Emulator . getIntUnixTimestamp ( ) ;
if ( ! time )
{
this . mutedHabbos . remove ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
return time ;
}
return false ;
}
public void habboEntered ( Habbo habbo )
{
habbo . getRoomUnit ( ) . animateWalk = false ;
synchronized ( this . currentBots )
{
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . getOwnerId ( ) )
return ;
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
botIterator . advance ( ) ;
if ( botIterator . value ( ) instanceof VisitorBot )
{
( ( VisitorBot ) botIterator . value ( ) ) . onUserEnter ( habbo ) ;
break ;
}
}
catch ( Exception e )
{
break ;
}
}
}
2018-12-22 11:39:00 +01:00
HabboItem doorTileTopItem = this . getTopItemAt ( habbo . getRoomUnit ( ) . getX ( ) , habbo . getRoomUnit ( ) . getY ( ) ) ;
2019-05-17 13:23:48 +02:00
if ( doorTileTopItem ! = null & & ! ( doorTileTopItem instanceof InteractionTeleportTile ) )
2018-12-22 11:39:00 +01:00
{
try
{
doorTileTopItem . onWalkOn ( habbo . getRoomUnit ( ) , this , new Object [ ] { } ) ;
} catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
}
}
2018-07-06 15:30:00 +02:00
}
public void floodMuteHabbo ( Habbo habbo , int timeOut )
{
habbo . getHabboStats ( ) . mutedCount + + ;
timeOut + = ( timeOut * ( int ) Math . ceil ( Math . pow ( habbo . getHabboStats ( ) . mutedCount , 2 ) ) ) ;
habbo . getHabboStats ( ) . chatCounter = 0 ;
habbo . mute ( timeOut ) ;
}
public void talk ( Habbo habbo , RoomChatMessage roomChatMessage , RoomChatType chatType )
{
this . talk ( habbo , roomChatMessage , chatType , false ) ;
}
public void talk ( final Habbo habbo , final RoomChatMessage roomChatMessage , RoomChatType chatType , boolean ignoreWired )
{
if ( ! habbo . getHabboStats ( ) . allowTalk ( ) )
return ;
2019-05-16 18:46:37 +02: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 15:30:00 +02:00
habbo . getHabboStats ( ) . chatCounter + = 2 ;
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) ! = this )
return ;
long millis = System . currentTimeMillis ( ) ;
if ( HABBO_CHAT_DELAY )
{
if ( millis - habbo . getHabboStats ( ) . lastChat < 750 )
{
return ;
}
}
habbo . getHabboStats ( ) . lastChat = millis ;
if ( roomChatMessage ! = null & & roomChatMessage . getMessage ( ) . equalsIgnoreCase ( " i am a pirate " ) )
{
Emulator . getThreading ( ) . run ( new YouAreAPirate ( habbo , this ) ) ;
return ;
}
UserIdleEvent event = new UserIdleEvent ( habbo , UserIdleEvent . IdleReason . TALKED , false ) ;
Emulator . getPluginManager ( ) . fireEvent ( event ) ;
if ( ! event . isCancelled ( ) )
{
if ( ! event . idle )
{
this . unIdle ( habbo ) ;
}
}
this . sendComposer ( new RoomUserTypingComposer ( habbo . getRoomUnit ( ) , false ) . compose ( ) ) ;
if ( roomChatMessage = = null | | roomChatMessage . getMessage ( ) = = null | | roomChatMessage . getMessage ( ) . equals ( " " ) )
return ;
for ( HabboItem area : this . getRoomSpecialTypes ( ) . getItemsOfType ( InteractionMuteArea . class ) )
{
if ( ( ( InteractionMuteArea ) area ) . inSquare ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) )
{
return ;
}
}
if ( ! this . wordFilterWords . isEmpty ( ) )
{
if ( ! habbo . hasPermission ( " acc_chat_no_filter " ) )
{
for ( String string : this . wordFilterWords )
{
roomChatMessage . setMessage ( roomChatMessage . getMessage ( ) . replace ( string , " bobba " ) ) ;
}
}
}
if ( ! habbo . hasPermission ( " acc_nomute " ) )
{
if ( this . isMuted ( ) & & ! this . hasRights ( habbo ) )
{
return ;
}
if ( this . isMuted ( habbo ) )
{
habbo . getClient ( ) . sendResponse ( new MutedWhisperComposer ( this . mutedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) - Emulator . getIntUnixTimestamp ( ) ) ) ;
return ;
}
}
if ( chatType ! = RoomChatType . WHISPER )
{
if ( CommandHandler . handleCommand ( habbo . getClient ( ) , roomChatMessage . getUnfilteredMessage ( ) ) )
{
WiredHandler . handle ( WiredTriggerType . SAY_COMMAND , habbo . getRoomUnit ( ) , habbo . getHabboInfo ( ) . getCurrentRoom ( ) , new Object [ ] { roomChatMessage . getMessage ( ) } ) ;
roomChatMessage . isCommand = true ;
return ;
}
if ( ! ignoreWired )
{
if ( WiredHandler . handle ( WiredTriggerType . SAY_SOMETHING , habbo . getRoomUnit ( ) , habbo . getHabboInfo ( ) . getCurrentRoom ( ) , new Object [ ] { roomChatMessage . getMessage ( ) } ) )
{
habbo . getClient ( ) . sendResponse ( new RoomUserWhisperComposer ( new RoomChatMessage ( roomChatMessage . getMessage ( ) , habbo , habbo , roomChatMessage . getBubble ( ) ) ) ) ;
return ;
}
}
}
ServerMessage prefixMessage = roomChatMessage . getHabbo ( ) . getHabboInfo ( ) . getRank ( ) . hasPrefix ( ) ? new RoomUserNameChangedComposer ( habbo , true ) . compose ( ) : null ;
ServerMessage clearPrefixMessage = prefixMessage ! = null ? new RoomUserNameChangedComposer ( habbo ) . compose ( ) : null ;
2018-09-28 21:25:00 +02:00
Rectangle show = this . roomSpecialTypes . tentAt ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) ;
2018-07-06 15:30:00 +02:00
if ( chatType = = RoomChatType . WHISPER )
{
if ( roomChatMessage . getTargetHabbo ( ) = = null )
{
return ;
}
final ServerMessage message = new RoomUserWhisperComposer ( roomChatMessage ) . compose ( ) ;
RoomChatMessage staffChatMessage = new RoomChatMessage ( roomChatMessage ) ;
staffChatMessage . setMessage ( " To " + staffChatMessage . getTargetHabbo ( ) . getHabboInfo ( ) . getUsername ( ) + " : " + staffChatMessage . getMessage ( ) ) ;
final ServerMessage staffMessage = new RoomUserWhisperComposer ( staffChatMessage ) . compose ( ) ;
for ( Habbo h : this . getHabbos ( ) )
{
if ( h = = roomChatMessage . getTargetHabbo ( ) | | h = = habbo )
{
2018-10-07 00:28:00 +02:00
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) )
2018-07-06 15:30:00 +02:00
{
if ( prefixMessage ! = null )
{
h . getClient ( ) . sendResponse ( prefixMessage ) ;
}
h . getClient ( ) . sendResponse ( message ) ;
if ( clearPrefixMessage ! = null )
{
h . getClient ( ) . sendResponse ( clearPrefixMessage ) ;
}
}
continue ;
}
if ( h . hasPermission ( " acc_see_whispers " ) )
{
h . getClient ( ) . sendResponse ( staffMessage ) ;
}
}
}
else if ( chatType = = RoomChatType . TALK )
{
ServerMessage message = new RoomUserTalkComposer ( roomChatMessage ) . compose ( ) ;
boolean noChatLimit = habbo . hasPermission ( " acc_chat_no_limit " ) ;
for ( Habbo h : this . getHabbos ( ) )
{
2018-09-28 21:25:00 +02:00
if ( ( h . getRoomUnit ( ) . getCurrentLocation ( ) . distance ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) < = this . chatDistance | |
2018-07-06 15:30:00 +02:00
h . equals ( habbo ) | |
this . hasRights ( h ) | |
2018-09-28 21:25:00 +02:00
noChatLimit ) & & ( show = = null | | RoomLayout . tileInSquare ( show , h . getRoomUnit ( ) . getCurrentLocation ( ) ) ) )
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) )
2018-07-06 15:30:00 +02:00
{
2018-12-22 11:39:00 +01:00
if ( prefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat )
2018-07-06 15:30:00 +02:00
{
h . getClient ( ) . sendResponse ( prefixMessage ) ;
}
h . getClient ( ) . sendResponse ( message ) ;
2018-12-22 11:39:00 +01:00
if ( clearPrefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat )
2018-07-06 15:30:00 +02:00
{
h . getClient ( ) . sendResponse ( clearPrefixMessage ) ;
}
}
}
}
}
else if ( chatType = = RoomChatType . SHOUT )
{
ServerMessage message = new RoomUserShoutComposer ( roomChatMessage ) . compose ( ) ;
for ( Habbo h : this . getHabbos ( ) )
{
2018-10-07 00:28:00 +02:00
if ( ! h . getHabboStats ( ) . userIgnored ( habbo . getHabboInfo ( ) . getId ( ) ) & & ( show = = null | | RoomLayout . tileInSquare ( show , h . getRoomUnit ( ) . getCurrentLocation ( ) ) ) )
2018-07-06 15:30:00 +02:00
{
2018-12-22 11:39:00 +01:00
if ( prefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) { h . getClient ( ) . sendResponse ( prefixMessage ) ; }
2018-07-06 15:30:00 +02:00
h . getClient ( ) . sendResponse ( message ) ;
2018-12-22 11:39:00 +01:00
if ( clearPrefixMessage ! = null & & ! h . getHabboStats ( ) . preferOldChat ) { h . getClient ( ) . sendResponse ( clearPrefixMessage ) ; }
2018-07-06 15:30:00 +02:00
}
}
}
if ( chatType = = RoomChatType . TALK | | chatType = = RoomChatType . SHOUT )
{
synchronized ( this . currentBots )
{
TIntObjectIterator < Bot > botIterator = this . currentBots . iterator ( ) ;
for ( int i = this . currentBots . size ( ) ; i - - > 0 ; )
{
try
{
botIterator . advance ( ) ;
Bot bot = botIterator . value ( ) ;
bot . onUserSay ( roomChatMessage ) ;
}
catch ( NoSuchElementException e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
break ;
}
}
}
2018-12-22 11:39:00 +01:00
if ( roomChatMessage . getBubble ( ) . triggersTalkingFurniture ( ) )
2018-07-06 15:30:00 +02:00
{
2018-12-22 11:39:00 +01:00
THashSet < HabboItem > items = this . roomSpecialTypes . getItemsOfType ( InteractionTalkingFurniture . class ) ;
2018-07-06 15:30:00 +02:00
2018-12-22 11:39:00 +01:00
for ( HabboItem item : items )
{
if ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) . distance ( habbo . getRoomUnit ( ) . getCurrentLocation ( ) ) < = Emulator . getConfig ( ) . getInt ( " furniture.talking.range " ) )
2018-07-06 15:30:00 +02:00
{
2018-12-22 11:39:00 +01:00
int count = Emulator . getConfig ( ) . getInt ( item . getBaseItem ( ) . getName ( ) + " .message.count " , 0 ) ;
2018-07-06 15:30:00 +02:00
2018-12-22 11:39:00 +01:00
if ( count > 0 )
{
int randomValue = Emulator . getRandom ( ) . nextInt ( count + 1 ) ;
2018-07-06 15:30:00 +02:00
2018-12-22 11:39:00 +01: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 15:30:00 +02:00
2018-12-22 11:39:00 +01:00
this . sendComposer ( new RoomUserShoutComposer ( itemMessage ) . compose ( ) ) ;
2018-07-06 15:30:00 +02:00
2018-12-22 11:39:00 +01:00
try
{
item . onClick ( habbo . getClient ( ) , this , new Object [ 0 ] ) ;
break ;
}
catch ( Exception e )
{
Emulator . getLogging ( ) . logErrorLine ( e ) ;
2018-07-06 15:30:00 +02:00
}
}
}
}
2018-12-22 11:39:00 +01:00
2018-07-06 15:30:00 +02:00
}
}
}
public THashSet < RoomTile > getLockedTiles ( )
{
2018-09-28 21:25:00 +02:00
THashSet < RoomTile > lockedTiles = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
HabboItem item ;
try
{
iterator . advance ( ) ;
item = iterator . value ( ) ;
}
catch ( Exception e )
{
break ;
}
if ( item . getBaseItem ( ) . getType ( ) ! = FurnitureType . FLOOR )
continue ;
boolean found = false ;
for ( RoomTile tile : lockedTiles )
{
if ( tile . x = = item . getX ( ) & &
2019-05-04 03:25:43 +02:00
tile . y = = item . getY ( ) )
2018-07-06 15:30:00 +02:00
{
found = true ;
break ;
}
}
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 + + )
{
RoomTile tile = this . layout . getTile ( ( short ) ( item . getX ( ) + x ) , ( short ) ( item . getY ( ) + y ) ) ;
if ( tile ! = null )
{
lockedTiles . add ( tile ) ;
}
}
}
}
else
{
for ( short y = 0 ; y < item . getBaseItem ( ) . getWidth ( ) ; y + + )
{
for ( short x = 0 ; x < item . getBaseItem ( ) . getLength ( ) ; x + + )
{
RoomTile tile = this . layout . getTile ( ( short ) ( item . getX ( ) + x ) , ( short ) ( item . getY ( ) + y ) ) ;
if ( tile ! = null )
{
lockedTiles . add ( tile ) ;
}
}
}
}
}
}
return lockedTiles ;
}
@Deprecated
public THashSet < HabboItem > getItemsAt ( int x , int y )
{
RoomTile tile = this . getLayout ( ) . getTile ( ( short ) x , ( short ) y ) ;
if ( tile ! = null )
{
return this . getItemsAt ( tile ) ;
}
2018-09-28 21:25:00 +02:00
return new THashSet < > ( 0 ) ;
2018-07-06 15:30:00 +02:00
}
public THashSet < HabboItem > getItemsAt ( RoomTile tile )
{
if ( this . loaded )
{
if ( this . tileCache . containsKey ( tile ) )
{
return this . tileCache . get ( tile ) ;
}
}
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( 0 ) ;
2018-07-06 15:30:00 +02:00
2019-05-18 17:47:28 +02:00
if ( tile = = null )
return items ;
2018-07-06 15:30:00 +02:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
HabboItem item ;
try
{
iterator . advance ( ) ;
item = iterator . value ( ) ;
}
catch ( Exception e )
{
break ;
}
2019-05-18 17:47:28 +02:00
if ( item = = null )
continue ;
2018-07-06 15:30:00 +02:00
if ( item . getBaseItem ( ) . getType ( ) ! = FurnitureType . FLOOR )
continue ;
if ( item . getX ( ) = = tile . x & & item . getY ( ) = = tile . y )
{
items . add ( item ) ;
}
else
{
if ( item . getBaseItem ( ) . getWidth ( ) < = 1 & & item . getBaseItem ( ) . getLength ( ) < = 1 )
{
continue ;
}
THashSet < RoomTile > tiles = this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
for ( RoomTile t : tiles )
{
if ( ( t . x = = tile . x ) & & ( t . y = = tile . y ) & & ( ! items . contains ( item ) ) )
{
items . add ( item ) ;
}
}
}
}
if ( this . loaded )
{
this . tileCache . put ( tile , items ) ;
}
return items ;
}
public THashSet < HabboItem > getItemsAt ( int x , int y , double minZ )
{
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
for ( HabboItem item : this . getItemsAt ( x , y ) )
{
if ( item . getZ ( ) < minZ )
continue ;
if ( item . getX ( ) = = x & & item . getY ( ) = = y & & item . getZ ( ) > = minZ )
{
items . add ( item ) ;
}
else
{
if ( item . getBaseItem ( ) . getWidth ( ) < = 1 & & item . getBaseItem ( ) . getLength ( ) < = 1 )
{
continue ;
}
THashSet < RoomTile > tiles = this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
for ( RoomTile tile : tiles )
{
if ( ( tile . x = = x ) & & ( tile . y = = y ) & & ( ! items . contains ( item ) ) ) {
items . add ( item ) ;
}
}
}
}
return items ;
}
public THashSet < HabboItem > getItemsAt ( Class < ? extends HabboItem > type , int x , int y )
{
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
2019-03-18 02:22:00 +01:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
HabboItem item ;
try
{
iterator . advance ( ) ;
item = iterator . value ( ) ;
} catch ( Exception e )
{
break ;
}
2018-07-06 15:30:00 +02:00
if ( item . getClass ( ) . equals ( type ) )
{
if ( item . getX ( ) = = x & & item . getY ( ) = = y )
{
items . add ( item ) ;
}
else
{
if ( item . getBaseItem ( ) . getWidth ( ) < = 1 & & item . getBaseItem ( ) . getLength ( ) < = 1 )
{
continue ;
}
THashSet < RoomTile > tiles = this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ;
for ( RoomTile tile : tiles ) {
if ( ( tile . x = = x ) & & ( tile . y = = y ) & & ( ! items . contains ( item ) ) ) {
items . add ( item ) ;
}
}
}
}
}
return items ;
}
2018-12-22 11:39:00 +01:00
public boolean hasItemsAt ( int x , int y )
{
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
HabboItem habboItem ;
try
{
iterator . advance ( ) ;
habboItem = iterator . value ( ) ;
} catch ( Exception e )
{
break ;
}
if ( habboItem . getX ( ) = = x & & habboItem . getY ( ) = = y ) return true ;
}
return false ;
}
2018-07-06 15:30:00 +02:00
public HabboItem getTopItemAt ( int x , int y )
{
return this . getTopItemAt ( x , y , null ) ;
}
public HabboItem getTopItemAt ( int x , int y , HabboItem exclude )
{
HabboItem item = null ;
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
HabboItem habboItem ;
try
{
iterator . advance ( ) ;
habboItem = iterator . value ( ) ;
}
catch ( Exception e )
{
break ;
}
if ( habboItem . getBaseItem ( ) . getType ( ) ! = FurnitureType . FLOOR )
continue ;
if ( exclude ! = null )
{
if ( exclude = = habboItem )
continue ;
}
if ( habboItem . getX ( ) = = x & & habboItem . getY ( ) = = y )
{
if ( item = = null | | ( habboItem . getZ ( ) + Item . getCurrentHeight ( habboItem ) ) > ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) )
{
item = habboItem ;
}
2019-05-12 09:59:01 +02:00
}
else
2018-07-06 15:30:00 +02:00
{
if ( habboItem . getBaseItem ( ) . getWidth ( ) < = 1 & & habboItem . getBaseItem ( ) . getLength ( ) < = 1 )
{
continue ;
}
THashSet < RoomTile > tiles = this . layout . getTilesAt (
this . layout . getTile ( habboItem . getX ( ) , habboItem . getY ( ) ) ,
habboItem . getBaseItem ( ) . getWidth ( ) ,
habboItem . getBaseItem ( ) . getLength ( ) ,
habboItem . getRotation ( ) ) ;
for ( RoomTile tile : tiles )
{
if ( ( ( tile . x = = x ) & & ( tile . y = = y ) ) )
{
if ( item = = null | | item . getZ ( ) < habboItem . getZ ( ) )
item = habboItem ;
}
}
}
}
return item ;
}
public double getTopHeightAt ( int x , int y )
{
2019-03-18 02:22:00 +01:00
HabboItem item = this . getTopItemAt ( x , y ) ;
2018-07-06 15:30:00 +02:00
if ( item ! = null )
2019-05-12 09:59:01 +02:00
return ( item . getZ ( ) + Item . getCurrentHeight ( item ) ) ;
2018-07-06 15:30:00 +02:00
else
return this . layout . getHeightAtSquare ( x , y ) ;
}
@Deprecated
public HabboItem getLowestChair ( int x , int y )
{
RoomTile tile = this . layout . getTile ( ( short ) x , ( short ) y ) ;
if ( tile ! = null )
{
2019-03-18 02:22:00 +01:00
return this . getLowestChair ( tile ) ;
2018-07-06 15:30:00 +02:00
}
return null ;
}
public HabboItem getLowestChair ( RoomTile tile )
{
HabboItem lowestChair = null ;
THashSet < HabboItem > items = this . getItemsAt ( tile ) ;
if ( items ! = null & & ! items . isEmpty ( ) )
{
for ( HabboItem item : items )
{
if ( item . getBaseItem ( ) . allowSit ( ) )
{
if ( lowestChair = = null | | item . getZ ( ) < lowestChair . getZ ( ) )
{
lowestChair = item ;
}
}
if ( lowestChair ! = null )
{
if ( item . getZ ( ) > lowestChair . getZ ( ) & & item . getZ ( ) - lowestChair . getZ ( ) < 1 . 5 )
{
lowestChair = null ;
}
}
}
}
return lowestChair ;
}
2018-12-22 11:39:00 +01:00
public double getStackHeight ( short x , short y , boolean calculateHeightmap , HabboItem exclude )
2018-07-06 15:30:00 +02:00
{
2019-05-15 19:00:43 +02:00
if ( x < 0 | | y < 0 | | this . layout = = null )
2018-12-22 11:39:00 +01:00
return calculateHeightmap ? Short . MAX_VALUE : 0 . 0 ;
2018-07-06 15:30:00 +02:00
double height = this . layout . getHeightAtSquare ( x , y ) ;
boolean canStack = true ;
boolean stackHelper = false ;
THashSet < HabboItem > items = this . getItemsAt ( x , y ) ;
if ( items ! = null )
{
for ( HabboItem item : items )
{
2018-12-22 11:39:00 +01:00
if ( item = = exclude ) continue ;
2018-07-06 15:30:00 +02:00
if ( item instanceof InteractionStackHelper )
{
stackHelper = true ;
height = item . getExtradata ( ) . isEmpty ( ) ? Double . valueOf ( " 0.0 " ) : ( Double . valueOf ( item . getExtradata ( ) ) / 100 ) ;
canStack = true ;
}
}
if ( ! stackHelper )
{
2018-12-22 11:39:00 +01:00
HabboItem item = this . getTopItemAt ( x , y , exclude ) ;
2019-03-18 02:22:00 +01:00
if ( item ! = null )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
canStack = item . getBaseItem ( ) . allowStack ( ) ;
height = item . getZ ( ) + Item . getCurrentHeight ( item ) ;
2018-12-22 11:39:00 +01:00
}
2019-05-12 09:59:01 +02:00
HabboItem lowestChair = this . getLowestChair ( x , y ) ;
2019-05-13 04:14:34 +02:00
if ( lowestChair ! = null & & lowestChair ! = exclude ) {
2019-05-12 09:59:01 +02:00
canStack = true ;
height = lowestChair . getZ ( ) + Item . getCurrentHeight ( lowestChair ) ;
}
2018-07-06 15:30:00 +02:00
}
}
if ( calculateHeightmap )
{
return ( canStack ? height * 256 . 0D : Short . MAX_VALUE ) ;
}
2018-12-22 11:39:00 +01:00
return canStack ? height : - 1 ;
2018-07-06 15:30:00 +02:00
}
2018-12-22 11:39:00 +01:00
public double getStackHeight ( short x , short y , boolean calculateHeightmap )
2018-07-06 15:30:00 +02:00
{
2018-12-22 11:39:00 +01:00
return this . getStackHeight ( x , y , calculateHeightmap , null ) ;
2018-07-06 15:30:00 +02:00
}
public boolean hasObjectTypeAt ( Class < ? > type , int x , int y )
{
THashSet < HabboItem > items = this . getItemsAt ( x , y ) ;
for ( HabboItem item : items )
{
if ( item . getClass ( ) = = type )
{
return true ;
}
}
return false ;
}
public boolean canSitOrLayAt ( int x , int y )
{
2019-03-18 02:22:00 +01:00
if ( this . hasHabbosAt ( x , y ) )
2018-07-06 15:30:00 +02:00
return false ;
2019-03-18 02:22:00 +01:00
THashSet < HabboItem > items = this . getItemsAt ( x , y ) ;
2018-07-06 15:30:00 +02:00
2019-03-18 02:22:00 +01:00
return this . canSitAt ( items ) | | this . canLayAt ( items ) ;
2018-07-06 15:30:00 +02:00
}
public boolean canSitAt ( int x , int y )
{
2019-03-18 02:22:00 +01:00
if ( this . hasHabbosAt ( x , y ) )
2018-07-06 15:30:00 +02:00
return false ;
return this . canSitAt ( this . getItemsAt ( x , y ) ) ;
}
boolean canWalkAt ( RoomTile roomTile )
{
if ( roomTile = = null )
{
return false ;
}
2018-11-17 14:28:00 +01:00
if ( roomTile . state = = RoomTileState . INVALID )
2018-07-06 15:30:00 +02:00
return false ;
HabboItem topItem = null ;
boolean canWalk = true ;
THashSet < HabboItem > items = this . getItemsAt ( roomTile ) ;
if ( items ! = null )
{
for ( HabboItem item : items )
{
if ( topItem = = null )
{
topItem = item ;
}
if ( item . getZ ( ) > topItem . getZ ( ) )
{
topItem = item ;
canWalk = topItem . isWalkable ( ) | | topItem . getBaseItem ( ) . allowWalk ( ) ;
}
else if ( item . getZ ( ) = = topItem . getZ ( ) & & canWalk )
{
if ( ( ! topItem . isWalkable ( ) & & ! topItem . getBaseItem ( ) . allowWalk ( ) ) | | ( ! item . getBaseItem ( ) . allowWalk ( ) & & ! item . isWalkable ( ) ) )
{
canWalk = false ;
}
}
}
}
return canWalk ;
}
boolean canSitAt ( THashSet < HabboItem > items )
{
if ( items = = null )
return false ;
HabboItem topItem = null ;
HabboItem lowestSitItem = null ;
boolean canSitUnder = false ;
for ( HabboItem item : items )
{
if ( ( lowestSitItem = = null | | lowestSitItem . getZ ( ) > item . getZ ( ) ) & & item . getBaseItem ( ) . allowSit ( ) )
{
lowestSitItem = item ;
2018-10-07 00:28:00 +02:00
canSitUnder = true ;
2018-07-06 15:30:00 +02:00
}
2018-10-07 00:28:00 +02:00
if ( lowestSitItem ! = null & & canSitUnder )
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
if ( item ! = lowestSitItem )
2018-07-06 15:30:00 +02:00
{
2018-10-07 00:28:00 +02:00
double distance = item . getZ ( ) - lowestSitItem . getZ ( ) ;
if ( distance > = 0 & & distance < 0 . 8 )
{
2018-07-06 15:30:00 +02:00
canSitUnder = false ;
2018-10-07 00:28:00 +02:00
}
2018-07-06 15:30:00 +02:00
}
}
2019-04-22 01:42:00 +02:00
if ( topItem = = null | | Item . getCurrentHeight ( item ) > Item . getCurrentHeight ( topItem ) )
2018-07-06 15:30:00 +02:00
{
topItem = item ;
}
}
if ( topItem = = null )
return false ;
if ( lowestSitItem = = null )
return false ;
if ( topItem = = lowestSitItem )
return true ;
return topItem . getZ ( ) < = lowestSitItem . getZ ( ) | | ( canSitUnder ) ;
}
public boolean canLayAt ( int x , int y )
{
return this . canLayAt ( this . getItemsAt ( x , y ) ) ;
}
boolean canLayAt ( THashSet < HabboItem > items )
{
if ( items = = null | | items . isEmpty ( ) )
return true ;
HabboItem topItem = null ;
for ( HabboItem item : items )
{
if ( ( topItem = = null | | item . getZ ( ) > topItem . getZ ( ) ) )
{
topItem = item ;
}
}
return ( topItem = = null | | topItem . getBaseItem ( ) . allowLay ( ) ) ;
}
public RoomTile getRandomWalkableTile ( )
{
for ( int i = 0 ; i < 10 ; i + + )
{
RoomTile tile = this . layout . getTile ( ( short ) ( Math . random ( ) * this . layout . getMapSizeX ( ) ) , ( short ) ( Math . random ( ) * this . layout . getMapSizeY ( ) ) ) ;
2018-10-07 00:28:00 +02:00
if ( tile . isWalkable ( ) )
2018-07-06 15:30:00 +02:00
{
return tile ;
}
}
return null ;
}
public Habbo getHabbo ( String username )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getHabboInfo ( ) . getUsername ( ) . equalsIgnoreCase ( username ) )
return habbo ;
}
return null ;
}
public Habbo getHabbo ( RoomUnit roomUnit )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getRoomUnit ( ) = = roomUnit )
return habbo ;
}
return null ;
}
public Habbo getHabbo ( int userId )
{
return this . currentHabbos . get ( userId ) ;
}
public Habbo getHabboByRoomUnitId ( int roomUnitId )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getRoomUnit ( ) . getId ( ) = = roomUnitId )
return habbo ;
}
return null ;
}
public void sendComposer ( ServerMessage message )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
habbo . getClient ( ) . sendResponse ( message ) ;
}
}
public void sendComposerToHabbosWithRights ( ServerMessage message )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
2019-03-18 02:22:00 +01:00
if ( this . hasRights ( habbo ) )
2018-07-06 15:30:00 +02:00
{
habbo . getClient ( ) . sendResponse ( message ) ;
}
}
}
public void petChat ( ServerMessage message )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( ! habbo . getHabboStats ( ) . ignorePets )
habbo . getClient ( ) . sendResponse ( message ) ;
}
}
public void botChat ( ServerMessage message )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( ! habbo . getHabboStats ( ) . ignoreBots )
habbo . getClient ( ) . sendResponse ( message ) ;
}
}
private void loadRights ( Connection connection )
{
this . rights . clear ( ) ;
try ( PreparedStatement statement = connection . prepareStatement ( " SELECT user_id FROM room_rights WHERE room_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
this . rights . add ( set . getInt ( " user_id " ) ) ;
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
private void loadBans ( Connection connection )
{
this . bannedHabbos . clear ( ) ;
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 = ? " ) )
{
statement . setInt ( 1 , Emulator . getIntUnixTimestamp ( ) ) ;
statement . setInt ( 2 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
if ( this . bannedHabbos . containsKey ( set . getInt ( " user_id " ) ) )
continue ;
this . bannedHabbos . put ( set . getInt ( " user_id " ) , new RoomBan ( set ) ) ;
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
//TODO: Return Enum
public int guildRightLevel ( Habbo habbo )
{
if ( this . guild > 0 & & habbo . getHabboStats ( ) . hasGuild ( this . guild ) )
{
Guild guild = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuild ( this . guild ) ;
if ( Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getOnlyAdmins ( guild ) . get ( habbo . getHabboInfo ( ) . getId ( ) ) ! = null )
return 3 ;
2019-05-12 07:35:08 +02:00
if ( guild . getRights ( ) )
2018-07-06 15:30:00 +02:00
{
return 2 ;
}
}
return 0 ;
}
public boolean isOwner ( Habbo habbo )
{
2018-09-12 18:45:00 +02:00
return habbo . getHabboInfo ( ) . getId ( ) = = this . ownerId | | habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) ;
2018-07-06 15:30:00 +02:00
}
public boolean hasRights ( Habbo habbo )
{
2019-03-18 02:22:00 +01: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 15:30:00 +02:00
}
public void giveRights ( Habbo habbo )
{
if ( habbo ! = null )
{
this . giveRights ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
}
public void giveRights ( int userId )
{
if ( this . rights . contains ( userId ) )
return ;
if ( this . rights . add ( userId ) )
{
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT INTO room_rights VALUES (?, ?) " ) )
{
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
Habbo habbo = this . getHabbo ( userId ) ;
if ( habbo ! = null )
{
this . refreshRightsForHabbo ( habbo ) ;
this . sendComposer ( new RoomAddRightsListComposer ( this , habbo . getHabboInfo ( ) . getId ( ) , habbo . getHabboInfo ( ) . getUsername ( ) ) . compose ( ) ) ;
}
else
{
Habbo owner = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( this . ownerId ) ;
if ( owner ! = null )
{
MessengerBuddy buddy = owner . getMessenger ( ) . getFriend ( userId ) ;
if ( buddy ! = null )
{
this . sendComposer ( new RoomAddRightsListComposer ( this , userId , buddy . getUsername ( ) ) . compose ( ) ) ;
}
}
}
}
public void removeRights ( int userId )
{
Habbo habbo = this . getHabbo ( userId ) ;
if ( Emulator . getPluginManager ( ) . fireEvent ( new UserRightsTakenEvent ( this . getHabbo ( this . getOwnerId ( ) ) , userId , habbo ) ) . isCancelled ( ) )
return ;
this . sendComposer ( new RoomRemoveRightsListComposer ( this , userId ) . compose ( ) ) ;
if ( this . rights . remove ( userId ) )
{
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_rights WHERE room_id = ? AND user_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , userId ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
if ( habbo ! = null )
{
2018-09-28 21:25:00 +02:00
habbo . getRoomUnit ( ) . setRightsLevel ( RoomRightLevels . NONE ) ;
habbo . getRoomUnit ( ) . removeStatus ( RoomUnitStatus . FLAT_CONTROL ) ;
2018-07-06 15:30:00 +02:00
this . refreshRightsForHabbo ( habbo ) ;
}
}
public void removeAllRights ( )
{
this . rights . clear ( ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_rights WHERE room_id = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
this . refreshRightsInRoom ( ) ;
}
void refreshRightsInRoom ( )
{
Room room = this ;
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) = = room )
{
2019-03-18 02:22:00 +01:00
this . refreshRightsForHabbo ( habbo ) ;
2018-07-06 15:30:00 +02:00
}
}
}
public void refreshRightsForHabbo ( Habbo habbo )
{
HabboItem item ;
RoomRightLevels flatCtrl = RoomRightLevels . NONE ;
2019-03-18 02:22:00 +01:00
if ( habbo . getHabboStats ( ) . isRentingSpace ( ) )
2018-07-06 15:30:00 +02:00
{
item = this . getHabboItem ( habbo . getHabboStats ( ) . getRentedItemId ( ) ) ;
if ( item ! = null )
{
return ;
}
}
2018-09-12 18:45:00 +02:00
if ( habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) )
2018-07-06 15:30:00 +02:00
{
habbo . getClient ( ) . sendResponse ( new RoomOwnerComposer ( ) ) ;
flatCtrl = RoomRightLevels . MODERATOR ;
}
else if ( this . isOwner ( habbo ) )
{
habbo . getClient ( ) . sendResponse ( new RoomOwnerComposer ( ) ) ;
flatCtrl = RoomRightLevels . MODERATOR ;
}
else if ( this . hasRights ( habbo ) & & ! this . hasGuild ( ) )
{
flatCtrl = RoomRightLevels . RIGHTS ;
}
else if ( this . hasGuild ( ) )
{
int level = this . guildRightLevel ( habbo ) ;
if ( level = = 3 )
{
flatCtrl = RoomRightLevels . GUILD_ADMIN ;
}
else if ( level = = 2 )
{
flatCtrl = RoomRightLevels . GUILD_RIGHTS ;
}
}
habbo . getClient ( ) . sendResponse ( new RoomRightsComposer ( flatCtrl ) ) ;
2018-09-12 18:45:00 +02:00
habbo . getRoomUnit ( ) . setStatus ( RoomUnitStatus . FLAT_CONTROL , flatCtrl . level + " " ) ;
2018-07-06 15:30:00 +02:00
habbo . getRoomUnit ( ) . setRightsLevel ( flatCtrl ) ;
2018-09-28 21:25:00 +02:00
habbo . getRoomUnit ( ) . statusUpdate ( true ) ;
2018-07-06 15:30:00 +02:00
if ( flatCtrl . equals ( RoomRightLevels . MODERATOR ) )
{
habbo . getClient ( ) . sendResponse ( new RoomRightsListComposer ( this ) ) ;
}
}
public THashMap < Integer , String > getUsersWithRights ( )
{
2018-09-28 21:25:00 +02:00
THashMap < Integer , String > rightsMap = new THashMap < > ( ) ;
2018-07-06 15:30:00 +02: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 = ? " ) )
{
statement . setInt ( 1 , this . id ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
rightsMap . put ( set . getInt ( " user_id " ) , set . getString ( " username " ) ) ;
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
return rightsMap ;
}
public void unbanHabbo ( int userId )
{
RoomBan ban = this . bannedHabbos . remove ( userId ) ;
if ( ban ! = null )
{
ban . delete ( ) ;
}
this . sendComposer ( new RoomUserUnbannedComposer ( this , userId ) . compose ( ) ) ;
}
public boolean isBanned ( Habbo habbo )
{
RoomBan ban = this . bannedHabbos . get ( habbo . getHabboInfo ( ) . getId ( ) ) ;
2018-09-12 18:45:00 +02:00
boolean banned = ban ! = null & & ban . endTimestamp > Emulator . getIntUnixTimestamp ( ) & & ! habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) & & ! habbo . hasPermission ( " acc_enteranyroom " ) ;
2018-07-06 15:30:00 +02:00
if ( ! banned & & ban ! = null )
{
this . unbanHabbo ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
return banned ;
}
public TIntObjectHashMap < RoomBan > getBannedHabbos ( )
{
return this . bannedHabbos ;
}
public void addRoomBan ( RoomBan roomBan )
{
this . bannedHabbos . put ( roomBan . userId , roomBan ) ;
}
public void makeSit ( Habbo habbo )
{
2018-09-12 18:45:00 +02:00
if ( habbo . getRoomUnit ( ) . hasStatus ( RoomUnitStatus . SIT ) )
2018-07-06 15:30:00 +02: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 18:45:00 +02:00
habbo . getRoomUnit ( ) . setStatus ( RoomUnitStatus . SIT , 0 . 5 + " " ) ;
2018-07-06 15:30:00 +02:00
this . sendComposer ( new RoomUserStatusComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
}
2019-03-18 02:22:00 +01:00
public void giveEffect ( Habbo habbo , int effectId , int duration )
2018-07-06 15:30:00 +02:00
{
if ( this . currentHabbos . containsKey ( habbo . getHabboInfo ( ) . getId ( ) ) )
{
2019-03-18 02:22:00 +01:00
this . giveEffect ( habbo . getRoomUnit ( ) , effectId , duration ) ;
2018-07-06 15:30:00 +02:00
}
}
2019-03-18 02:22:00 +01:00
public void giveEffect ( RoomUnit roomUnit , int effectId , int duration )
2018-07-06 15:30:00 +02:00
{
2019-04-22 01:42:00 +02:00
if ( duration = = - 1 | | duration = = Integer . MAX_VALUE )
2019-03-18 02:22:00 +01:00
{
duration = Integer . MAX_VALUE ;
}
else
{
duration + = Emulator . getIntUnixTimestamp ( ) ;
}
2018-12-22 11:39:00 +01:00
if ( this . allowEffects & & roomUnit ! = null )
2018-07-06 15:30:00 +02:00
{
2019-03-18 02:22:00 +01:00
roomUnit . setEffectId ( effectId , duration ) ;
2018-07-06 15:30:00 +02:00
this . sendComposer ( new RoomUserEffectComposer ( roomUnit ) . compose ( ) ) ;
}
}
public void giveHandItem ( Habbo habbo , int handItem )
{
2019-03-18 02:22:00 +01:00
this . giveHandItem ( habbo . getRoomUnit ( ) , handItem ) ;
2018-12-22 11:39:00 +01:00
}
public void giveHandItem ( RoomUnit roomUnit , int handItem )
{
roomUnit . setHandItem ( handItem ) ;
this . sendComposer ( new RoomUserHandItemComposer ( roomUnit ) . compose ( ) ) ;
2018-07-06 15:30:00 +02: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 )
{
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 ( ) ) ) ;
}
else if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . WALL )
{
this . sendComposer ( new WallItemUpdateComposer ( item ) . compose ( ) ) ;
}
}
}
}
}
public void updateItemState ( HabboItem item )
{
2018-09-12 18:45:00 +02:00
if ( ! item . isLimited ( ) )
{
this . sendComposer ( new ItemStateComposer ( item ) . compose ( ) ) ;
}
else
{
this . sendComposer ( new FloorItemUpdateComposer ( item ) . compose ( ) ) ;
}
2018-07-06 15:30:00 +02:00
if ( item . getBaseItem ( ) . getType ( ) = = FurnitureType . FLOOR )
{
this . updateTiles ( this . getLayout ( ) . getTilesAt ( this . layout . getTile ( item . getX ( ) , item . getY ( ) ) , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , item . getRotation ( ) ) ) ;
}
}
public int getUserFurniCount ( int userId )
{
return this . furniOwnerCount . get ( userId ) ;
}
public void ejectUserFurni ( int userId )
{
2018-09-28 21:25:00 +02:00
THashSet < HabboItem > items = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( Exception e )
{
break ;
}
if ( iterator . value ( ) . getUserId ( ) = = userId )
{
items . add ( iterator . value ( ) ) ;
iterator . value ( ) . setRoomId ( 0 ) ;
}
}
Habbo habbo = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( userId ) ;
if ( habbo ! = null )
{
habbo . getInventory ( ) . getItemsComponent ( ) . addItems ( items ) ;
habbo . getClient ( ) . sendResponse ( new AddHabboItemComposer ( items ) ) ;
}
for ( HabboItem i : items )
{
this . pickUpItem ( i , null ) ;
}
}
public void ejectUserItem ( HabboItem item )
{
this . pickUpItem ( item , null ) ;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public void ejectAll ( )
{
this . ejectAll ( null ) ;
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
public void ejectAll ( Habbo habbo )
{
2018-09-28 21:25:00 +02:00
THashMap < Integer , THashSet < HabboItem > > userItemsMap = new THashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
synchronized ( this . roomItems )
{
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( Exception e )
{
break ;
}
if ( habbo ! = null & & iterator . value ( ) . getUserId ( ) = = habbo . getHabboInfo ( ) . getId ( ) )
continue ;
if ( userItemsMap . get ( iterator . value ( ) . getUserId ( ) ) = = null )
{
2018-09-28 21:25:00 +02:00
userItemsMap . put ( iterator . value ( ) . getUserId ( ) , new THashSet < > ( ) ) ;
2018-07-06 15:30:00 +02:00
}
userItemsMap . get ( iterator . value ( ) . getUserId ( ) ) . add ( iterator . value ( ) ) ;
}
}
for ( Map . Entry < Integer , THashSet < HabboItem > > entrySet : userItemsMap . entrySet ( ) )
{
for ( HabboItem i : entrySet . getValue ( ) )
{
this . pickUpItem ( i , null ) ;
}
Habbo user = Emulator . getGameEnvironment ( ) . getHabboManager ( ) . getHabbo ( entrySet . getKey ( ) ) ;
if ( user ! = null )
{
user . getInventory ( ) . getItemsComponent ( ) . addItems ( entrySet . getValue ( ) ) ;
user . getClient ( ) . sendResponse ( new AddHabboItemComposer ( entrySet . getValue ( ) ) ) ;
}
}
}
public void refreshGuild ( Guild guild )
{
if ( guild . getRoomId ( ) = = this . id )
{
2019-05-18 15:44:12 +02:00
THashSet < GuildMember > members = Emulator . getGameEnvironment ( ) . getGuildManager ( ) . getGuildMembers ( guild . getId ( ) ) ;
2018-07-06 15:30:00 +02:00
for ( Habbo habbo : this . getHabbos ( ) )
{
2019-05-18 15:44:12 +02: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 15:30:00 +02:00
}
}
this . refreshGuildRightsInRoom ( ) ;
}
public void refreshGuildColors ( Guild guild )
{
if ( guild . getRoomId ( ) = = this . id )
{
TIntObjectIterator < HabboItem > iterator = this . roomItems . iterator ( ) ;
for ( int i = this . roomItems . size ( ) ; i - - > 0 ; )
{
try
{
iterator . advance ( ) ;
}
catch ( Exception e )
{
break ;
}
HabboItem habboItem = iterator . value ( ) ;
2019-03-18 02:22:00 +01:00
if ( habboItem instanceof InteractionGuildFurni )
2018-07-06 15:30:00 +02:00
{
if ( ( ( InteractionGuildFurni ) habboItem ) . getGuildId ( ) = = guild . getId ( ) )
this . updateItem ( habboItem ) ;
}
}
}
}
public void refreshGuildRightsInRoom ( )
{
for ( Habbo habbo : this . getHabbos ( ) )
{
if ( habbo . getHabboInfo ( ) . getCurrentRoom ( ) = = this )
{
if ( habbo . getHabboInfo ( ) . getId ( ) ! = this . ownerId )
{
2018-09-12 18:45:00 +02:00
if ( ! ( habbo . hasPermission ( Permission . ACC_ANYROOMOWNER ) | | habbo . hasPermission ( " acc_moverotate " ) ) )
2019-03-18 02:22:00 +01:00
this . refreshRightsForHabbo ( habbo ) ;
2018-07-06 15:30:00 +02:00
}
}
}
}
public void idle ( Habbo habbo )
{
habbo . getRoomUnit ( ) . setIdle ( ) ;
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2018-12-22 11:39:00 +01:00
WiredHandler . handle ( WiredTriggerType . IDLES , habbo . getRoomUnit ( ) , this , new Object [ ] { habbo } ) ;
2018-07-06 15:30:00 +02:00
}
public void unIdle ( Habbo habbo )
{
habbo . getRoomUnit ( ) . resetIdleTimer ( ) ;
this . sendComposer ( new RoomUnitIdleComposer ( habbo . getRoomUnit ( ) ) . compose ( ) ) ;
2018-12-22 11:39:00 +01:00
WiredHandler . handle ( WiredTriggerType . UNIDLES , habbo . getRoomUnit ( ) , this , new Object [ ] { habbo } ) ;
2018-07-06 15:30:00 +02:00
}
public void dance ( Habbo habbo , DanceType danceType )
{
2018-09-12 18:45:00 +02:00
this . dance ( habbo . getRoomUnit ( ) , danceType ) ;
}
public void dance ( RoomUnit unit , DanceType danceType )
{
2019-03-18 02:22:00 +01:00
boolean isDancing = ! unit . getDanceType ( ) . equals ( DanceType . NONE ) ;
2018-09-12 18:45:00 +02:00
unit . setDanceType ( danceType ) ;
this . sendComposer ( new RoomUserDanceComposer ( unit ) . compose ( ) ) ;
2019-03-18 02:22:00 +01:00
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 } ) ;
}
2018-07-06 15:30:00 +02:00
}
public void addToWordFilter ( String word )
{
synchronized ( this . wordFilterWords )
{
if ( this . wordFilterWords . contains ( word ) )
return ;
2019-03-18 02:22:00 +01:00
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " INSERT IGNORE INTO room_wordfilter VALUES (?, ?) " ) )
2018-07-06 15:30:00 +02:00
{
statement . setInt ( 1 , this . getId ( ) ) ;
statement . setString ( 2 , word ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
2019-03-18 02:22:00 +01:00
return ;
2018-07-06 15:30:00 +02:00
}
2019-03-18 02:22:00 +01:00
this . wordFilterWords . add ( word ) ;
2018-07-06 15:30:00 +02:00
}
}
public void removeFromWordFilter ( String word )
{
synchronized ( this . wordFilterWords )
{
this . wordFilterWords . remove ( word ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( " DELETE FROM room_wordfilter WHERE room_id = ? AND word = ? " ) )
{
statement . setInt ( 1 , this . getId ( ) ) ;
statement . setString ( 2 , word ) ;
statement . execute ( ) ;
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
}
}
public THashSet < WiredHighscoreData > getWiredHighscoreData ( WiredHighscoreScoreType scoreType , WiredHighscoreClearType clearType )
{
if ( ! this . wiredHighscoreData . containsKey ( scoreType ) )
{
this . loadWiredHighscoreData ( scoreType , clearType ) ;
}
return this . wiredHighscoreData . get ( scoreType ) . get ( clearType ) ;
}
public void loadWiredHighscoreData ( WiredHighscoreScoreType scoreType , WiredHighscoreClearType clearType )
{
this . wiredHighscoreData . clear ( ) ;
2018-09-28 21:25:00 +02:00
THashSet < WiredHighscoreData > wiredData = new THashSet < > ( ) ;
2018-07-06 15:30:00 +02:00
try
{
String query = " SELECT " +
" SUM(score + team_score) as total_score, " +
" COUNT(*) as wins, " +
" users.username, " +
" room_game_scores.*, " +
" GROUP_CONCAT(users.username) as usernames " +
" FROM room_game_scores " +
" INNER JOIN users ON room_game_scores.user_id = users.id " +
" WHERE room_id = ? AND game_start_timestamp >= ? " ;
int timestamp = 0 ;
if ( clearType ! = WiredHighscoreClearType . ALLTIME )
{
if ( clearType = = WiredHighscoreClearType . MONTHLY )
{
timestamp = Emulator . getIntUnixTimestamp ( ) - ( 31 * 24 * 60 * 60 ) ;
}
else if ( clearType = = WiredHighscoreClearType . WEEKLY )
{
timestamp = Emulator . getIntUnixTimestamp ( ) - ( 7 * 24 * 60 * 60 ) ;
}
else if ( clearType = = WiredHighscoreClearType . DAILY )
{
timestamp = Emulator . getIntUnixTimestamp ( ) - ( 24 * 60 * 60 ) ;
}
}
2018-07-08 23:32:00 +02:00
2018-07-06 15:30:00 +02:00
if ( scoreType = = WiredHighscoreScoreType . CLASSIC )
{
query + = " GROUP BY game_start_timestamp, user_id, team_id ORDER BY total_score DESC " ;
}
else if ( scoreType = = WiredHighscoreScoreType . MOSTWIN )
{
query + = " GROUP BY game_start_timestamp, game_name, team_id ORDER BY wins DESC, total_score ASC " ;
}
else if ( scoreType = = WiredHighscoreScoreType . PERTEAM )
{
query + = " GROUP BY game_start_timestamp, team_id ORDER BY team_score DESC " ;
}
query + = " LIMIT " + Emulator . getConfig ( ) . getValue ( " wired.highscores.displaycount " ) ;
try ( Connection connection = Emulator . getDatabase ( ) . getDataSource ( ) . getConnection ( ) ; PreparedStatement statement = connection . prepareStatement ( query ) )
{
statement . setInt ( 1 , this . id ) ;
statement . setInt ( 2 , timestamp ) ;
try ( ResultSet set = statement . executeQuery ( ) )
{
while ( set . next ( ) )
{
wiredData . add ( new WiredHighscoreData ( set . getString ( " usernames " ) . split ( " , " ) , set . getInt ( " score " ) , set . getInt ( " team_score " ) , set . getInt ( " total_score " ) ) ) ;
}
}
}
}
catch ( SQLException e )
{
Emulator . getLogging ( ) . logSQLException ( e ) ;
}
2018-09-28 21:25:00 +02:00
THashMap < WiredHighscoreClearType , THashSet < WiredHighscoreData > > dataMap = new THashMap < > ( ) ;
2018-07-06 15:30:00 +02:00
dataMap . put ( clearType , wiredData ) ;
this . wiredHighscoreData . put ( scoreType , dataMap ) ;
}
public void handleWordQuiz ( Habbo habbo , String answer )
{
synchronized ( this . userVotes )
{
if ( ! this . wordQuiz . isEmpty ( ) & & ! this . hasVotedInWordQuiz ( habbo ) )
{
answer = answer . replace ( " : " , " " ) ;
if ( answer . equals ( " 0 " ) )
{
this . noVotes + + ;
}
else if ( answer . equals ( " 1 " ) )
{
this . yesVotes + + ;
}
this . sendComposer ( new SimplePollAnswerComposer ( habbo . getHabboInfo ( ) . getId ( ) , answer , this . noVotes , this . yesVotes ) . compose ( ) ) ;
this . userVotes . add ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
}
}
public void startWordQuiz ( String question , int duration )
{
2019-03-18 02:22:00 +01:00
if ( ! this . hasActiveWordQuiz ( ) )
2018-07-06 15:30:00 +02: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 ( ) ) ;
}
}
public boolean hasActiveWordQuiz ( )
{
return Emulator . getIntUnixTimestamp ( ) < this . wordQuizEnd ;
}
public boolean hasVotedInWordQuiz ( Habbo habbo )
{
return this . userVotes . contains ( habbo . getHabboInfo ( ) . getId ( ) ) ;
}
public void alert ( String message )
{
this . sendComposer ( new GenericAlertComposer ( message ) . compose ( ) ) ;
}
public int itemCount ( )
{
return this . roomItems . size ( ) ;
}
public void setJukeBoxActive ( boolean jukeBoxActive )
{
this . jukeboxActive = jukeBoxActive ;
this . needsUpdate = true ;
}
2018-09-28 21:25:00 +02:00
public boolean isHideWired ( )
{
return this . hideWired ;
}
public void setHideWired ( boolean hideWired )
{
this . hideWired = hideWired ;
if ( this . hideWired )
{
ServerMessage response = null ;
for ( HabboItem item : this . roomSpecialTypes . getTriggers ( ) )
{
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
for ( HabboItem item : this . roomSpecialTypes . getEffects ( ) )
{
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
for ( HabboItem item : this . roomSpecialTypes . getConditions ( ) )
{
2018-12-22 11:39:00 +01:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
for ( HabboItem item : this . roomSpecialTypes . getExtras ( ) )
{
2018-09-28 21:25:00 +02:00
this . sendComposer ( new RemoveFloorItemComposer ( item ) . compose ( ) ) ;
}
}
else
{
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 11:39:00 +01:00
this . sendComposer ( new RoomFloorItemsComposer ( this . furniOwnerNames , this . roomSpecialTypes . getExtras ( ) ) . compose ( ) ) ;
}
}
public FurnitureMovementError canPlaceFurnitureAt ( HabboItem item , Habbo habbo , RoomTile tile , int rotation )
{
2019-04-22 01:42:00 +02:00
rotation % = 8 ;
if ( this . hasRights ( habbo ) | | this . guildRightLevel ( habbo ) > = 2 | | habbo . hasPermission ( Permission . ACC_MOVEROTATE ) )
2018-12-22 11:39:00 +01:00
{
return FurnitureMovementError . NONE ;
}
2019-03-18 02:22:00 +01:00
if ( habbo . getHabboStats ( ) . isRentingSpace ( ) )
2018-12-22 11:39:00 +01:00
{
HabboItem rentSpace = this . getHabboItem ( habbo . getHabboStats ( ) . rentedItemId ) ;
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 ) ) )
{
return FurnitureMovementError . NO_RIGHTS ;
}
else
{
return FurnitureMovementError . NONE ;
}
}
2018-09-28 21:25:00 +02:00
}
2018-12-22 11:39:00 +01:00
return FurnitureMovementError . NO_RIGHTS ;
2018-09-28 21:25:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-04-22 01:42:00 +02:00
public FurnitureMovementError furnitureFitsAt ( RoomTile tile , HabboItem item , int rotation )
2018-12-22 11:39:00 +01:00
{
2019-05-03 05:08:27 +02:00
if ( ! this . layout . fitsOnMap ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) )
return FurnitureMovementError . INVALID_MOVE ;
2018-12-22 11:39:00 +01:00
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
2019-05-04 03:25:43 +02:00
for ( RoomTile t : occupiedTiles ) {
2018-12-22 11:39:00 +01:00
2019-05-04 03:25:43 +02:00
if ( this . hasHabbosAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_HABBOS ;
if ( this . hasBotsAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_BOTS ;
if ( this . hasPetsAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_PETS ;
}
2018-12-22 11:39:00 +01:00
2019-05-09 04:02:41 +02:00
boolean magicTile = item instanceof InteractionStackHelper ;
2019-04-22 01:42:00 +02:00
2019-05-09 04:02:41 +02:00
if ( ! magicTile ) {
List < Pair < RoomTile , THashSet < HabboItem > > > tileFurniList = new ArrayList < > ( ) ;
for ( RoomTile t : occupiedTiles ) {
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
HabboItem topItem = this . getTopItemAt ( t . x , t . y , item ) ;
if ( topItem ! = null & & ! topItem . getBaseItem ( ) . allowStack ( ) & & ! t . getAllowStack ( ) ) {
return FurnitureMovementError . CANT_STACK ;
}
2019-04-22 01:42:00 +02:00
}
2018-12-22 11:39:00 +01:00
2019-05-09 04:02:41 +02:00
if ( ! item . canStackAt ( this , tileFurniList ) ) {
return FurnitureMovementError . CANT_STACK ;
}
2018-12-22 11:39:00 +01:00
}
2019-04-22 01:42:00 +02:00
return FurnitureMovementError . NONE ;
}
public FurnitureMovementError placeFloorFurniAt ( HabboItem item , RoomTile tile , int rotation , Habbo owner ) throws Exception
{
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePlacedEvent . class , true ) )
{
Event furniturePlacedEvent = new FurniturePlacedEvent ( item , owner , tile ) ;
Emulator . getPluginManager ( ) . fireEvent ( furniturePlacedEvent ) ;
if ( furniturePlacedEvent . isCancelled ( ) )
return FurnitureMovementError . CANCEL_PLUGIN_PLACE ;
}
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
FurnitureMovementError fits = furnitureFitsAt ( tile , item , rotation ) ;
if ( ! fits . equals ( FurnitureMovementError . NONE ) )
{
return fits ;
}
2018-12-22 11:39:00 +01:00
item . setZ ( tile . getStackHeight ( ) ) ;
item . setX ( tile . x ) ;
item . setY ( tile . y ) ;
item . setRotation ( rotation ) ;
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) & & owner ! = null )
{
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 ( ) ) ;
for ( RoomTile t : occupiedTiles )
{
this . updateHabbosAt ( t . x , t . y ) ;
2019-05-12 16:41:57 +02:00
this . updateBotsAt ( t . x , t . y ) ;
2018-12-22 11:39:00 +01:00
}
Emulator . getThreading ( ) . run ( item ) ;
return FurnitureMovementError . NONE ;
}
public FurnitureMovementError placeWallFurniAt ( HabboItem item , String wallPosition , Habbo owner )
{
2019-03-18 02:22:00 +01:00
if ( ! ( this . hasRights ( owner ) | | this . guildRightLevel ( owner ) > = 2 ) )
{
return FurnitureMovementError . NO_RIGHTS ;
}
2018-12-22 11:39:00 +01:00
if ( Emulator . getPluginManager ( ) . isRegistered ( FurniturePlacedEvent . class , true ) )
{
Event furniturePlacedEvent = new FurniturePlacedEvent ( item , owner , null ) ;
Emulator . getPluginManager ( ) . fireEvent ( furniturePlacedEvent ) ;
if ( furniturePlacedEvent . isCancelled ( ) )
return FurnitureMovementError . CANCEL_PLUGIN_PLACE ;
}
item . setWallPosition ( wallPosition ) ;
if ( ! this . furniOwnerNames . containsKey ( item . getUserId ( ) ) & & owner ! = null )
{
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 ;
}
public FurnitureMovementError moveFurniTo ( HabboItem item , RoomTile tile , int rotation , Habbo actor )
{
RoomTile oldLocation = this . layout . getTile ( item . getX ( ) , item . getY ( ) ) ;
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureMovedEvent . class , true ) )
{
if ( Emulator . getPluginManager ( ) . fireEvent ( new FurnitureMovedEvent ( item , actor , oldLocation , tile ) ) . isCancelled ( ) )
return FurnitureMovementError . CANCEL_PLUGIN_MOVE ;
}
HabboItem topItem = this . getTopItemAt ( tile . x , tile . y ) ;
2019-03-18 02:22:00 +01:00
boolean magicTile = item instanceof InteractionStackHelper ;
2018-12-22 11:39:00 +01:00
//Check if can be placed at new position
THashSet < RoomTile > occupiedTiles = this . layout . getTilesAt ( tile , item . getBaseItem ( ) . getWidth ( ) , item . getBaseItem ( ) . getLength ( ) , rotation ) ;
if ( topItem ! = item )
{
for ( RoomTile t : occupiedTiles )
{
2019-03-18 02:22:00 +01:00
if ( ! magicTile & & ( ( this . getTopItemAt ( t . x , t . y ) ! = item ? t . state . equals ( RoomTileState . INVALID ) | | ! t . getAllowStack ( ) : this . calculateTileState ( t , item ) . equals ( RoomTileState . INVALID ) ) ) )
2018-12-22 11:39:00 +01:00
return FurnitureMovementError . CANT_STACK ;
if ( this . hasHabbosAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_HABBOS ;
if ( this . hasBotsAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_BOTS ;
if ( this . hasPetsAt ( t . x , t . y ) ) return FurnitureMovementError . TILE_HAS_PETS ;
}
}
List < Pair < RoomTile , THashSet < HabboItem > > > tileFurniList = new ArrayList < > ( ) ;
for ( RoomTile t : occupiedTiles )
{
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
}
2019-03-18 02:22:00 +01:00
if ( ! magicTile & & ! item . canStackAt ( this , tileFurniList ) )
2018-12-22 11:39:00 +01: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 ) ;
2019-04-22 01:42:00 +02:00
if ( oldRotation ! = rotation )
{
if ( Emulator . getPluginManager ( ) . isRegistered ( FurnitureRotatedEvent . class , true ) )
2018-12-22 11:39:00 +01:00
{
2019-04-22 01:42:00 +02:00
Event furnitureRotatedEvent = new FurnitureRotatedEvent ( item , actor , oldRotation ) ;
Emulator . getPluginManager ( ) . fireEvent ( furnitureRotatedEvent ) ;
if ( furnitureRotatedEvent . isCancelled ( ) )
{
item . setRotation ( oldRotation ) ;
return FurnitureMovementError . CANCEL_PLUGIN_ROTATE ;
}
2018-12-22 11:39:00 +01:00
}
}
//Place at new position
item . setX ( tile . x ) ;
item . setY ( tile . y ) ;
item . setZ ( this . getStackHeight ( tile . x , tile . y , false , item ) ) ;
2019-03-18 02:22:00 +01:00
if ( magicTile )
{
item . setZ ( tile . z ) ;
2019-04-22 01:42:00 +02:00
item . setExtradata ( " " + item . getZ ( ) * 100 ) ;
2019-03-18 02:22:00 +01:00
}
2018-12-22 11:39:00 +01:00
if ( item . getZ ( ) > 40d )
{
item . setZ ( 40 ) ;
}
2019-03-18 02:22:00 +01:00
//Update Furniture
item . onMove ( this , oldLocation , tile ) ;
item . needsUpdate ( true ) ;
Emulator . getThreading ( ) . run ( item ) ;
this . sendComposer ( new FloorItemUpdateComposer ( item ) . compose ( ) ) ;
2018-12-22 11:39:00 +01:00
//Update old & new tiles
occupiedTiles . removeAll ( oldOccupiedTiles ) ;
2019-03-18 02:22:00 +01:00
occupiedTiles . addAll ( oldOccupiedTiles ) ;
2018-12-22 11:39:00 +01:00
this . updateTiles ( occupiedTiles ) ;
//Update Habbos at old position
for ( RoomTile t : occupiedTiles )
{
this . updateHabbosAt ( t . x , t . y ) ;
2019-05-12 16:41:57 +02:00
this . updateBotsAt ( t . x , t . y ) ;
2018-12-22 11:39:00 +01:00
}
return FurnitureMovementError . NONE ;
}
2019-04-22 01:42:00 +02:00
public FurnitureMovementError slideFurniTo ( HabboItem item , RoomTile tile , int rotation )
{
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 < > ( ) ;
for ( RoomTile t : occupiedTiles )
{
tileFurniList . add ( Pair . create ( t , this . getItemsAt ( t ) ) ) ;
}
if ( ! magicTile & & ! item . canStackAt ( this , tileFurniList ) )
{
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
if ( magicTile )
{
item . setZ ( tile . z ) ;
item . setExtradata ( " " + item . getZ ( ) * 100 ) ;
}
if ( item . getZ ( ) > 40d )
{
item . setZ ( 40 ) ;
}
2019-05-01 03:55:21 +02: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-22 01:42:00 +02:00
//Update Habbos at old position
for ( RoomTile t : occupiedTiles )
{
this . updateHabbosAt ( t . x , t . y ) ;
2019-05-12 16:41:57 +02:00
this . updateBotsAt ( t . x , t . y ) ;
2019-04-22 01:42:00 +02:00
}
return FurnitureMovementError . NONE ;
}
2019-05-18 17:32:13 +02:00
public THashSet < RoomUnit > getRoomUnits ( ) {
THashSet < RoomUnit > units = new THashSet < > ( ) ;
2018-12-22 11:39:00 +01:00
2019-05-18 17:32:13 +02:00
for ( Habbo habbo : this . currentHabbos . values ( ) ) {
if ( habbo ! = null & & habbo . getRoomUnit ( ) ! = null & & habbo . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) ) {
units . add ( habbo . getRoomUnit ( ) ) ;
}
}
for ( Pet pet : this . currentPets . valueCollection ( ) ) {
if ( pet ! = null & & pet . getRoomUnit ( ) ! = null & & pet . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) ) {
units . add ( pet . getRoomUnit ( ) ) ;
}
}
for ( Bot bot : this . currentBots . valueCollection ( ) ) {
if ( bot ! = null & & bot . getRoomUnit ( ) ! = null & & bot . getRoomUnit ( ) . getRoom ( ) . getId ( ) = = this . getId ( ) ) {
units . add ( bot . getRoomUnit ( ) ) ;
}
}
return units ;
}
2019-05-04 03:25:43 +02:00
}