Merge branch 'dev' into Snaiker/Arcturus-Community-patch-fix-issue-934

This commit is contained in:
Remco 2021-02-07 22:19:43 +01:00
commit a93aad2b66
82 changed files with 1978 additions and 1023 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM maven:latest AS builder
# Copy the Emulator sources to the container
COPY . .
# Package it
RUN mvn package && mv /target/Habbo*-with-dependencies.jar /target/Habbo.jar
# Use Java 8 for running
FROM java:8 AS runner
# Copy the generated source
COPY --from=builder /target/Habbo.jar /
# Save the script to wait for the database, among running the Arcturus Emulator
RUN echo "#!/bin/bash \n java -Dfile.encoding=UTF-8 -jar /Habbo.jar" > /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Run the Emulator with Java
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -101,6 +101,8 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscr
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('subscriptions.hc.payday.message', 'Woohoo HC Payday has arrived! You have received %amount% credits to your purse. Enjoy!');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.roomuser.idle.not_dancing.ignore.wired_idle', '0');
-- OPTIONAL HC MIGRATION
-- INSERT INTO users_subscriptions SELECT NULL, user_id, 'HABBO_CLUB' as `subscription_type`, UNIX_TIMESTAMP() AS `timestamp_start`, (club_expire_timestamp - UNIX_TIMESTAMP()) AS `duration`, 1 AS `active` FROM users_settings WHERE club_expire_timestamp > UNIX_TIMESTAMP();
@ -114,3 +116,13 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`;
-- Permissions to see tent chat
ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`;
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent');
-- Roombadge command
ALTER TABLE `permissions` ADD `cmd_roombadge` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `cmd_massbadge`;
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_roombadge.no_badge', 'No badge specified!');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_roombadge', 'roombadge');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_roombadge', ':roombadge <badge>');
-- Making items.wired_data column bigger since wired data is saved as JSON now
ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000);

View File

@ -0,0 +1,6 @@
-- Wired variables for bots
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.name', '%name%');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.roomname', '%roomname%');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.user_count', '%user_count%');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.owner', '%owner%');
INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.item_count', '%item_count%');

View File

@ -144,8 +144,8 @@ public class CleanerThread implements Runnable {
if (Emulator.isReady) {
for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) {
habbo.getHabboStats().petRespectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect");
habbo.getHabboStats().respectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect.pets");
habbo.getHabboStats().respectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect");
habbo.getHabboStats().petRespectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect.pets");
}
}
}

View File

@ -194,11 +194,11 @@ public class Bot implements Runnable {
}
String message = this.chatLines.get(this.lastChatIndex)
.replace("%owner%", this.room.getOwnerName())
.replace("%item_count%", this.room.itemCount() + "")
.replace("%name%", this.name)
.replace("%roomname%", this.room.getName())
.replace("%user_count%", this.room.getUserCount() + "");
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), this.room.getOwnerName())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), this.room.itemCount() + "")
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.name)
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), this.room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), this.room.getUserCount() + "");
if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{ message })) {
this.talk(message);

View File

@ -58,58 +58,76 @@ public class ButlerBot extends Bot {
@Override
public void onUserSay(final RoomChatMessage message) {
if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || this.getRoom() == null) {
return;
}
double distanceBetweenBotAndHabbo = this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation());
if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) {
if (this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance"))
if (message.getUnfilteredMessage() != null) {
for (Map.Entry<THashSet<String>, Integer> set : serveItems.entrySet()) {
for (String s : set.getKey()) {
if (message.getUnfilteredMessage().toLowerCase().contains(s)) {
for (String keyword : set.getKey()) {
// Check if the string contains a certain keyword using a regex.
// If keyword = tea, teapot wouldn't trigger it.
if (message.getUnfilteredMessage().toLowerCase().matches("\\b" + keyword + "\\b")) {
// Enable plugins to cancel this event
BotServerItemEvent serveEvent = new BotServerItemEvent(this, message.getHabbo(), set.getValue());
if (Emulator.getPluginManager().fireEvent(serveEvent).isCancelled()) {
return;
}
// Start give handitem process
if (this.getRoomUnit().canWalk()) {
final String key = s;
final Bot b = this;
b.lookAt(serveEvent.habbo);
final String key = keyword;
final Bot bot = this;
final List<Runnable> tasks = new ArrayList();
// Step 1: Look at Habbo
bot.lookAt(serveEvent.habbo);
// Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo
final List<Runnable> tasks = new ArrayList<>();
tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0));
tasks.add(() -> {
if(this.getRoom() != null) {
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
b.talk(msg);
String botMessage = Emulator.getTexts()
.getValue("bots.butler.given")
.replace("%key%", key)
.replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{ botMessage })) {
bot.talk(botMessage);
}
}
});
List<Runnable> failedReached = new ArrayList();
List<Runnable> failedReached = new ArrayList<>();
failedReached.add(() -> {
if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) {
for (Runnable t : tasks) {
t.run();
if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) {
for (Runnable task : tasks) {
task.run();
}
}
});
// Give bot the handitem that it's going to give the Habbo
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) {
if (distanceBetweenBotAndHabbo > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) {
Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)));
} else {
Emulator.getThreading().run(failedReached.get(0), 1000);
}
} else {
this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId);
if(this.getRoom() != null) {
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId);
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
this.talk(msg);
}
@ -120,5 +138,6 @@ public class ButlerBot extends Bot {
}
}
}
}
}
}

View File

@ -16,7 +16,7 @@ public class AboutCommand extends Command {
}
public static String credits = "Arcturus Morningstar is an opensource project based on Arcturus By TheGeneral \n" +
"The Following people have all contributed to this emulator:\n" +
" TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper";
" TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Rasmus\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper";
@Override
public boolean handle(GameClient gameClient, String[] params) {

View File

@ -217,6 +217,7 @@ public class CommandHandler {
addCommand(new LayCommand());
addCommand(new MachineBanCommand());
addCommand(new MassBadgeCommand());
addCommand(new RoomBadgeCommand());
addCommand(new MassCreditsCommand());
addCommand(new MassGiftCommand());
addCommand(new MassPixelsCommand());

View File

@ -0,0 +1,54 @@
package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.users.inventory.BadgesComponent;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.users.AddUserBadgeComposer;
import gnu.trove.map.hash.THashMap;
public class RoomBadgeCommand extends Command {
public RoomBadgeCommand() {
super("cmd_roombadge", Emulator.getTexts().getValue("commands.keys.cmd_roombadge").split(";"));
}
@Override
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (gameClient == null)
return true;
if (params.length == 2) {
String badge;
badge = params[1];
if (!badge.isEmpty()) {
THashMap<String, String> keys = new THashMap<>();
keys.put("display", "BUBBLE");
keys.put("image", "${image.library.url}album1584/" + badge + ".gif");
keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received"));
ServerMessage message = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose();
for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getHabbos()) {
if (habbo.isOnline()) {
if (habbo.getInventory() != null && habbo.getInventory().getBadgesComponent() != null && !habbo.getInventory().getBadgesComponent().hasBadge(badge)) {
HabboBadge b = BadgesComponent.createBadge(badge, habbo);
habbo.getClient().sendResponse(new AddUserBadgeComposer(b));
habbo.getClient().sendResponse(message);
}
}
}
}
return true;
}
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_roombadge.no_badge"), RoomChatMessageBubbles.ALERT);
return true;
}
}

View File

@ -45,7 +45,7 @@ public class UserInfoCommand extends Command {
Emulator.getTexts().getValue("command.cmd_userinfo.online") + ": " + (onlineHabbo == null ? Emulator.getTexts().getValue("generic.no") : Emulator.getTexts().getValue("generic.yes")) + "\r" +
((habbo.getRank().hasPermission(Permission.ACC_HIDE_MAIL, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.email") + ": " + habbo.getMail() + "\r") +
((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_register") + ": " + habbo.getIpRegister() + "\r") +
((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getClient().getChannel().remoteAddress().toString() + "\r") +
((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getHabboInfo().getIpLogin() + "\r") +
(onlineHabbo != null ? Emulator.getTexts().getValue("command.cmd_userinfo.achievement_score") + ": " + onlineHabbo.getHabboStats().achievementScore + "\r" : ""));
ModToolBan ban = Emulator.getGameEnvironment().getModToolManager().checkForBan(habbo.getId());

View File

@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
@ -7,6 +8,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.rooms.RoomUnitType;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -32,7 +35,11 @@ public class InteractionEffectTile extends InteractionPressurePlate {
@Override
public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOff(roomUnit, room, objects);
Emulator.getThreading().run(() -> updateState(room), 100);
if(objects != null && objects.length > 0) {
WiredHandler.handle(WiredTriggerType.WALKS_OFF_FURNI, roomUnit, room, new Object[]{this});
}
}
@Override

View File

@ -5,14 +5,28 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class InteractionFireworks extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionFireworks.class);
private static final String STATE_EMPTY = "0"; // Not used since the removal of pixels
private static final String STATE_CHARGED = "1";
private static final String STATE_EXPLOSION = "2";
public class InteractionFireworks extends HabboItem {
public InteractionFireworks(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -26,35 +40,103 @@ public class InteractionFireworks extends HabboItem {
return false;
}
@Override
public boolean isWalkable() {
return this.getBaseItem().allowWalk();
}
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
}
@Override
public void serializeExtradata(ServerMessage serverMessage) {
serverMessage.appendInt((this.isLimited() ? 256 : 0));
serverMessage.appendString(this.getExtradata());
super.serializeExtradata(serverMessage); //Design flaw ;(
}
/**
* Checked in Habbo on 2021-01-03
* - Fireworks should be charged to be able to detonate them
* - Habbos with Rights can detonate fireworks from anywhere in a room
* - Habbos without rights have to walk to an adjecent tile to be able to detonate (see Interaction Switch)
* - Wired can always detonate fireworks
*/
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
super.onClick(client, room, objects);
if (room == null)
return;
if (client != null && this.getExtradata().equalsIgnoreCase("2")) //2 explodes I think (0 = empty, 1 = charged, 2 = effect)
{
AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger"));
// Wireds can always detonate fireworks if charged
if (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE) {
if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) {
super.onClick(client, room, objects);
if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) {
this.reCharge(room);
}
}
return;
}
if (client == null)
return;
// Habbos without rights have to walk to an adjecent tile to be able to detonate the fireworks
if (!this.canToggle(client.getHabbo(), room)) {
RoomTile closestTile = null;
for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) {
if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) {
closestTile = tile;
}
}
if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) {
List<Runnable> onSuccess = new ArrayList<>();
onSuccess.add(() -> {
try {
this.onClick(client, room, objects);
} catch (Exception e) {
e.printStackTrace();
}
});
client.getHabbo().getRoomUnit().setGoalLocation(closestTile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>()));
}
}
if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) {
super.onClick(client, room, objects);
if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION))
{
this.reCharge(room);
AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger"));
}
}
}
@Override
public boolean allowWiredResetState() {
return true;
return false;
}
@Override
public void onPlace(Room room) {
super.onPlace(room);
this.setExtradata(STATE_CHARGED);
}
@Override
public boolean canToggle(Habbo habbo, Room room) {
return room.hasRights(habbo) || RoomLayout.tilesAdjecent(
room.getLayout().getTile(this.getX(), this.getY()),
habbo.getRoomUnit().getCurrentLocation()
);
}
private void reCharge(Room room) {
// Default = 5000, Nuclear Firework should have 10000 in its custom params according to Habbo
int explodeDuration = 5000;
if (!this.getBaseItem().getCustomParams().isEmpty()) {
try {
explodeDuration = Integer.parseInt(this.getBaseItem().getCustomParams());
} catch (NumberFormatException e) {
LOGGER.error("Incorrect customparams (" + this.getBaseItem().getCustomParams() + ") for base item ID (" + this.getBaseItem().getId() + ") of type (" + this.getBaseItem().getName() + ")");
}
}
Emulator.getThreading().run(() -> {
this.setExtradata(STATE_CHARGED);
this.needsUpdate(true);
room.updateItemState(this);
}, explodeDuration);
}
}

View File

@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.games.GameTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -63,7 +64,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
String[] data = set.getString("extra_data").split("\t");
if (data.length >= 2) {
this.baseTime = Integer.valueOf(data[1]);
this.baseTime = Integer.parseInt(data[1]);
this.timeNow = this.baseTime;
}
@ -149,33 +150,6 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
if (this.needsUpdate() || this.needsDelete()) {
super.run();
}
if (this.getRoomId() == 0) {
this.threadActive = false;
return;
}
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null || !this.isRunning || this.isPaused) {
this.threadActive = false;
return;
}
this.timeNow--;
if (this.timeNow < 0) this.timeNow = 0;
if (this.timeNow > 0) {
this.threadActive = true;
Emulator.getThreading().run(this, 1000);
} else {
this.threadActive = false;
this.timeNow = 0;
this.endGame(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
room.updateItem(this);
}
@Override
@ -248,7 +222,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this, 1000);
Emulator.getThreading().run(new GameTimer(this), 1000);
}
} else if (client != null) {
if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER)))
@ -271,7 +245,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this);
Emulator.getThreading().run(new GameTimer(this));
}
}
} else {
@ -285,7 +259,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
if (!this.threadActive) {
this.threadActive = true;
Emulator.getThreading().run(this, 1000);
Emulator.getThreading().run(new GameTimer(this), 1000);
}
}
@ -350,10 +324,30 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
}
public boolean isRunning() {
return isRunning;
return this.isRunning;
}
public void setRunning(boolean running) {
isRunning = running;
this.isRunning = running;
}
public void setThreadActive(boolean threadActive) {
this.threadActive = threadActive;
}
public boolean isPaused() {
return this.isPaused;
}
public void reduceTime() {
this.timeNow--;
}
public int getTimeNow() {
return this.timeNow;
}
public void setTimeNow(int timeNow) {
this.timeNow = timeNow;
}
}

View File

@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -64,18 +65,29 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.startDate + "\t" + this.endDate;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.startDate,
this.endDate
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (data.length == 2) {
try {
this.startDate = Integer.valueOf(data[0]);
this.endDate = Integer.valueOf(data[1]);
} catch (Exception e) {
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.startDate = data.startDate;
this.endDate = data.endDate;
} else {
String[] data = wiredData.split("\t");
if (data.length == 2) {
try {
this.startDate = Integer.parseInt(data[0]);
this.endDate = Integer.parseInt(data[1]);
} catch (Exception e) {
}
}
}
}
@ -85,4 +97,14 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
this.startDate = 0;
this.endDate = 0;
}
static class JsonData {
int startDate;
int endDate;
public JsonData(int startDate, int endDate) {
this.startDate = startDate;
this.endDate = endDate;
}
}
}

View File

@ -15,6 +15,8 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAS_FURNI;
@ -58,30 +60,43 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":");
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split(":");
String wiredData = set.getString("wired_data");
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.all = data.all;
if (data.length == 2) {
String[] items = data[1].split(";");
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (item != null) {
this.items.add(item);
}
}
if (item != null)
this.items.add(item);
} else {
String[] data = wiredData.split(":");
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (data.length == 2) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -166,4 +181,14 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
this.items.remove(item);
}
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
}

View File

@ -14,13 +14,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO;
@ -66,33 +66,43 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":");
for (HabboItem item : this.items) {
data.append(item.getId()).append(";");
}
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(":");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.all = data.all;
if (data.length >= 1) {
this.all = (data[0].equals("1"));
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (data.length == 2) {
String[] items = data[1].split(";");
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (item != null)
this.items.add(item);
if (data.length == 2) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -170,4 +180,14 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.items.remove(item);
}
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
}

View File

@ -14,6 +14,8 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.STUFF_IS;
@ -55,23 +57,37 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder();
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(";");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (String s : data)
this.items.add(room.getHabboItem(Integer.valueOf(s)));
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@Override
@ -138,4 +154,12 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -34,15 +35,26 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.lowerLimit + ":" + this.upperLimit;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split(":");
String wiredData = set.getString("wired_data");
this.lowerLimit = Integer.valueOf(data[0]);
this.upperLimit = Integer.valueOf(data[1]);
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit;
} else {
String[] data = wiredData.split(":");
this.lowerLimit = Integer.parseInt(data[0]);
this.upperLimit = Integer.parseInt(data[1]);
}
}
@Override
@ -82,4 +94,14 @@ public class WiredConditionHabboCount extends InteractionWiredCondition {
return true;
}
static class JsonData {
int lowerLimit;
int upperLimit;
public JsonData(int lowerLimit, int upperLimit) {
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -32,12 +33,21 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.effectId + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.effectId
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.effectId = Integer.valueOf(set.getString("wired_data"));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
}
}
@Override
@ -73,4 +83,12 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition {
return true;
}
static class JsonData {
int effectId;
public JsonData(int effectId) {
this.effectId = effectId;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import org.slf4j.Logger;
@ -66,13 +67,22 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.handItem + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.handItem
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
try {
this.handItem = Integer.valueOf(set.getString("wired_data"));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.handItem = data.handItemId;
} else {
this.handItem = Integer.parseInt(wiredData);
}
} catch (Exception e) {
LOGGER.error("Caught exception", e);
}
@ -82,4 +92,12 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition {
public void onPickUp() {
this.handItem = 0;
}
static class JsonData {
int handItemId;
public JsonData(int handItemId) {
this.handItemId = handItemId;
}
}
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -44,12 +45,21 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.badge;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.badge
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.badge = set.getString("wired_data");
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.badge = data.badge;
} else {
this.badge = wiredData;
}
}
@Override
@ -85,4 +95,12 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition {
return true;
}
static class JsonData {
String badge;
public JsonData(String badge) {
this.badge = badge;
}
}
}

View File

@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -32,16 +33,23 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.cycles + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.cycles
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String data = set.getString("wired_data");
String wiredData = set.getString("wired_data");
try {
if (!data.equals(""))
this.cycles = Integer.valueOf(data);
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
this.cycles = Integer.parseInt(wiredData);
}
} catch (Exception e) {
}
}
@ -80,4 +88,12 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition {
return true;
}
static class JsonData {
int cycles;
public JsonData(int cycles) {
this.cycles = cycles;
}
}
}

View File

@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
@ -15,8 +16,10 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class WiredConditionMatchStatePosition extends InteractionWiredCondition {
public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings {
public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT;
private THashSet<WiredMatchFurniSetting> settings;
@ -138,38 +141,42 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
@Override
public String getWiredData() {
StringBuilder data = new StringBuilder(this.settings.size() + ":");
if (this.settings.isEmpty()) {
data.append("\t;");
} else {
for (WiredMatchFurniSetting item : this.settings)
data.append(item.toString()).append(";");
}
data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0);
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.state,
this.position,
this.direction,
new ArrayList<>(this.settings)
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split(":");
String wiredData = set.getString("wired_data");
int itemCount = Integer.valueOf(data[0]);
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.state = data.state;
this.position = data.position;
this.direction = data.direction;
this.settings.addAll(data.settings);
} else {
String[] data = wiredData.split(":");
String[] items = data[1].split(";");
int itemCount = Integer.parseInt(data[0]);
for (int i = 0; i < itemCount; i++) {
String[] stuff = items[i].split("-");
String[] items = data[1].split(";");
if (stuff.length >= 5)
this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4])));
for (int i = 0; i < itemCount; i++) {
String[] stuff = items[i].split("-");
if (stuff.length >= 5)
this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4])));
}
this.state = data[2].equals("1");
this.direction = data[3].equals("1");
this.position = data[4].equals("1");
}
this.state = data[2].equals("1");
this.direction = data[3].equals("1");
this.position = data[4].equals("1");
}
@Override
@ -198,4 +205,38 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
}
}
}
@Override
public THashSet<WiredMatchFurniSetting> getMatchFurniSettings() {
return this.settings;
}
@Override
public boolean shouldMatchState() {
return this.state;
}
@Override
public boolean shouldMatchRotation() {
return this.direction;
}
@Override
public boolean shouldMatchPosition() {
return this.position;
}
static class JsonData {
boolean state;
boolean position;
boolean direction;
List<WiredMatchFurniSetting> settings;
public JsonData(boolean state, boolean position, boolean direction, List<WiredMatchFurniSetting> settings) {
this.state = state;
this.position = position;
this.direction = direction;
this.settings = settings;
}
}
}

View File

@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -32,16 +33,23 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.cycles + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.cycles
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String data = set.getString("wired_data");
String wiredData = set.getString("wired_data");
try {
if (!data.equals(""))
this.cycles = Integer.valueOf(data);
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.cycles = data.cycles;
} else {
if (!wiredData.equals(""))
this.cycles = Integer.parseInt(wiredData);
}
} catch (Exception e) {
}
}
@ -80,4 +88,12 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition {
return true;
}
static class JsonData {
int cycles;
public JsonData(int cycles) {
this.cycles = cycles;
}
}
}

View File

@ -16,6 +16,8 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_FURNI;
@ -59,32 +61,43 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":");
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(":");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.all = data.all;
if (data.length >= 1) {
this.all = (data[0].equals("1"));
for (int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (data.length == 2) {
String[] items = data[1].split(";");
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (item != null)
this.items.add(item);
if (data.length == 2) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -175,4 +188,14 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
//return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR;
return WiredConditionOperator.AND;
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
}

View File

@ -14,13 +14,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO;
@ -66,33 +66,43 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":");
for (HabboItem item : this.items) {
data.append(item.getId()).append(";");
}
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.all,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(":");
if (wiredData.startsWith("{")) {
WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
this.all = data.all;
if (data.length >= 1) {
this.all = (data[0].equals("1"));
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (data.length == 2) {
String[] items = data[1].split(";");
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (data.length >= 1) {
this.all = (data[0].equals("1"));
if (item != null)
this.items.add(item);
if (data.length == 2) {
String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -169,4 +179,14 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.items.remove(item);
}
}
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
}

View File

@ -14,6 +14,8 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS;
@ -50,23 +52,37 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder();
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(";");
if (wiredData.startsWith("{")) {
WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
for (String s : data)
this.items.add(room.getHabboItem(Integer.valueOf(s)));
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = set.getString("wired_data").split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@Override
@ -138,4 +154,12 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
this.items.remove(item);
}
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -34,14 +35,25 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.lowerLimit + ":" + this.upperLimit;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.lowerLimit,
this.upperLimit
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split(":");
this.lowerLimit = Integer.valueOf(data[0]);
this.upperLimit = Integer.valueOf(data[1]);
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
WiredConditionHabboCount.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionHabboCount.JsonData.class);
this.lowerLimit = data.lowerLimit;
this.upperLimit = data.upperLimit;
} else {
String[] data = wiredData.split(":");
this.lowerLimit = Integer.parseInt(data[0]);
this.upperLimit = Integer.parseInt(data[1]);
}
}
@Override
@ -81,4 +93,14 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition {
return true;
}
static class JsonData {
int lowerLimit;
int upperLimit;
public JsonData(int lowerLimit, int upperLimit) {
this.lowerLimit = lowerLimit;
this.upperLimit = upperLimit;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -32,12 +33,21 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.effectId + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.effectId
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.effectId = Integer.valueOf(set.getString("wired_data"));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.effectId = data.effectId;
} else {
this.effectId = Integer.parseInt(wiredData);
}
}
@Override
@ -73,4 +83,12 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition {
return true;
}
static class JsonData {
int effectId;
public JsonData(int effectId) {
this.effectId = effectId;
}
}
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboBadge;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -45,12 +46,21 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
@Override
public String getWiredData() {
return this.badge;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.badge
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.badge = set.getString("wired_data");
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.badge = data.badge;
} else {
this.badge = wiredData;
}
}
@Override
@ -86,4 +96,12 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition
return true;
}
static class JsonData {
String badge;
public JsonData(String badge) {
this.badge = badge;
}
}
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -39,16 +40,23 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.teamColor.type + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.teamColor
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String data = set.getString("wired_data");
try {
if (!data.equals(""))
this.teamColor = GameTeamColors.values()[Integer.valueOf(data)];
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
}
} catch (Exception e) {
this.teamColor = GameTeamColors.RED;
}
@ -88,4 +96,12 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
return true;
}
static class JsonData {
GameTeamColors teamColor;
public JsonData(GameTeamColors teamColor) {
this.teamColor = teamColor;
}
}
}

View File

@ -1,192 +1,32 @@
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition {
public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStatePosition {
public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT;
private THashSet<WiredMatchFurniSetting> settings;
private boolean state;
private boolean position;
private boolean rotation;
public WiredConditionNotMatchStatePosition(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.settings = new THashSet<>();
}
public WiredConditionNotMatchStatePosition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.settings = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (this.settings.isEmpty())
return true;
THashSet<WiredMatchFurniSetting> s = new THashSet<>();
for (WiredMatchFurniSetting setting : this.settings) {
HabboItem item = room.getHabboItem(setting.item_id);
if (item != null) {
boolean stateMatches = !this.state || item.getExtradata().equals(setting.state);
boolean positionMatches = !this.position || (setting.x == item.getX() && setting.y == item.getY());
boolean directionMatches = !this.rotation || setting.rotation == item.getRotation();
if (!stateMatches || !positionMatches || !directionMatches)
return true;
} else {
s.add(setting);
}
}
if (!s.isEmpty()) {
for (WiredMatchFurniSetting setting : s) {
this.settings.remove(setting);
}
}
return false;
}
@Override
public String getWiredData() {
StringBuilder data = new StringBuilder(this.settings.size() + ":");
if (this.settings.isEmpty()) {
data.append("\t;");
} else {
for (WiredMatchFurniSetting item : this.settings)
data.append(item.toString()).append(";");
}
data.append(":").append(this.state ? 1 : 0).append(":").append(this.rotation ? 1 : 0).append(":").append(this.position ? 1 : 0);
return data.toString();
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split(":");
int itemCount = Integer.valueOf(data[0]);
String[] items = data[1].split(";");
for (int i = 0; i < itemCount; i++) {
String[] stuff = items[i].split("-");
if (stuff.length >= 5)
this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4])));
}
this.state = data[2].equals("1");
this.rotation = data[3].equals("1");
this.position = data[4].equals("1");
}
@Override
public void onPickUp() {
this.settings.clear();
this.state = false;
this.rotation = false;
this.position = false;
return !super.execute(roomUnit, room, stuff);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public void serializeWiredData(ServerMessage message, Room room) {
this.refresh();
message.appendBoolean(false);
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.settings.size());
for (WiredMatchFurniSetting item : this.settings)
message.appendInt(item.item_id);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
message.appendInt(4);
message.appendInt(this.state ? 1 : 0);
message.appendInt(this.rotation ? 1 : 0);
message.appendInt(this.position ? 1 : 0);
message.appendInt(10);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(0);
message.appendInt(0);
}
@Override
public boolean saveData(ClientMessage packet) {
packet.readInt();
this.state = packet.readInt() == 1;
this.rotation = packet.readInt() == 1;
this.position = packet.readInt() == 1;
packet.readString();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
return true;
int count = packet.readInt();
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.settings.clear();
for (int i = 0; i < count; i++) {
int itemId = packet.readInt();
HabboItem item = room.getHabboItem(itemId);
if (item != null)
this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY()));
}
return true;
}
private void refresh() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
THashSet<WiredMatchFurniSetting> remove = new THashSet<>();
for (WiredMatchFurniSetting setting : this.settings) {
HabboItem item = room.getHabboItem(setting.item_id);
if (item == null) {
remove.add(setting);
}
}
for (WiredMatchFurniSetting setting : remove) {
this.settings.remove(setting);
}
}
}
}

View File

@ -1,26 +1,16 @@
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomLayout;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition {
public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni {
public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI;
private THashSet<HabboItem> items = new THashSet<>();
public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@ -31,112 +21,19 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (roomUnit == null) return false;
if (roomUnit == null)
return false;
this.refresh();
if (this.items.isEmpty())
return true;
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
return this.items.stream().noneMatch(itemsAtUser::contains);
}
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder();
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
return data.toString();
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String[] data = set.getString("wired_data").split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (item != null) {
this.items.add(item);
}
}
}
@Override
public void onPickUp() {
this.items.clear();
return !triggerOnFurni(roomUnit, room);
}
@Override
public WiredConditionType getType() {
return type;
}
@Override
public void serializeWiredData(ServerMessage message, Room room) {
this.refresh();
message.appendBoolean(false);
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
for (HabboItem item : this.items)
message.appendInt(item.getId());
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(0);
message.appendInt(0);
}
@Override
public boolean saveData(ClientMessage packet) {
packet.readInt();
packet.readString();
int count = packet.readInt();
if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false;
this.items.clear();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room != null) {
for (int i = 0; i < count; i++) {
HabboItem item = room.getHabboItem(packet.readInt());
if (item != null) {
this.items.add(item);
}
}
}
return true;
}
private void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null) {
items.addAll(this.items);
} else {
for (HabboItem item : this.items) {
if (item.getRoomId() != room.getId())
items.add(item);
}
}
this.items.removeAll(items);
}
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -41,16 +42,23 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
@Override
public String getWiredData() {
return this.teamColor.type + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.teamColor
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String data = set.getString("wired_data");
try {
if (!data.equals(""))
this.teamColor = GameTeamColors.values()[Integer.valueOf(data)];
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.teamColor = data.teamColor;
} else {
if (!wiredData.equals(""))
this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)];
}
} catch (Exception e) {
this.teamColor = GameTeamColors.RED;
}
@ -90,4 +98,12 @@ public class WiredConditionTeamMember extends InteractionWiredCondition {
return true;
}
static class JsonData {
GameTeamColors teamColor;
public JsonData(GameTeamColors teamColor) {
this.teamColor = teamColor;
}
}
}

View File

@ -16,11 +16,13 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
private THashSet<HabboItem> items = new THashSet<>();
protected THashSet<HabboItem> items = new THashSet<>();
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -40,10 +42,14 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
if (this.items.isEmpty())
return false;
return triggerOnFurni(roomUnit, room);
}
protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) {
/*
* 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles.
* 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items
* */
* 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles.
* 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items
* */
if (!roomUnit.isWalking()) {
THashSet<HabboItem> itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
return this.items.stream().anyMatch(itemsAtUser::contains);
@ -67,27 +73,35 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override
public String getWiredData() {
this.refresh();
StringBuilder data = new StringBuilder();
for (HabboItem item : this.items) {
data.append(item.getId()).append(";");
}
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(";");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
for(int id : data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
}
@ -148,7 +162,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return true;
}
private void refresh() {
protected void refresh() {
THashSet<HabboItem> items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
@ -168,4 +182,12 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
public WiredConditionOperator operator() {
return WiredConditionOperator.AND;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -97,10 +97,15 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
message = message.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "")
.replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
message = message.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "")
.replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "")
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "")
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName)
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + "");
}
List<Bot> bots = room.getBots(this.botName);

View File

@ -116,10 +116,15 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
if (habbo != null) {
String m = this.message;
m = m.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "")
.replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
m = m.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "")
.replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "")
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "")
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName)
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + "");
List<Bot> bots = room.getBots(this.botName);

View File

@ -9,6 +9,7 @@ import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer;
@ -70,7 +71,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
packet.readInt();
try {
this.amount = Integer.valueOf(packet.readString());
this.amount = Integer.parseInt(packet.readString());
} catch (Exception e) {
return false;
}
@ -103,20 +104,26 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
@Override
public String getWiredData() {
return this.getDelay() + "\t" + this.amount;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay(), this.amount));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String wireData = set.getString("wired_data");
String wiredData = set.getString("wired_data");
this.amount = 0;
if (wireData.split("\t").length >= 2) {
super.setDelay(Integer.valueOf(wireData.split("\t")[0]));
if(wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.amount = data.amount;
} else {
if (wiredData.split("\t").length >= 2) {
super.setDelay(Integer.parseInt(wiredData.split("\t")[0]));
try {
this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]);
} catch (Exception e) {
try {
this.amount = Integer.parseInt(wiredData.split("\t")[1]);
} catch (Exception e) {
}
}
}
}
@ -131,4 +138,14 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
int delay;
int amount;
public JsonData(int delay, int amount) {
this.delay = delay;
this.amount = amount;
}
}
}

View File

@ -2,9 +2,9 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class WiredEffectMatchFurni extends InteractionWiredEffect {
public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings {
private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMatchFurni.class);
private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT;
@ -241,6 +241,26 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
}
}
@Override
public THashSet<WiredMatchFurniSetting> getMatchFurniSettings() {
return this.settings;
}
@Override
public boolean shouldMatchState() {
return this.state;
}
@Override
public boolean shouldMatchRotation() {
return this.direction;
}
@Override
public boolean shouldMatchPosition() {
return this.position;
}
static class JsonData {
boolean state;
boolean direction;

View File

@ -21,6 +21,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.FLEE;
@ -98,32 +99,40 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (this.items != null && !this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (item != null)
this.items.add(item);
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -206,4 +215,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.MOVE_FURNI_TO;
@ -123,24 +124,23 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
@Override
public String getWiredData() {
THashSet<HabboItem> items = new THashSet<>();
THashSet<HabboItem> itemsToRemove = new THashSet<>();
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
items.add(item);
itemsToRemove.add(item);
}
for (HabboItem item : items) {
for (HabboItem item : itemsToRemove) {
this.items.remove(item);
}
StringBuilder data = new StringBuilder(this.direction + "\t" + this.spacing + "\t" + this.getDelay() + "\t");
for (HabboItem item : this.items) {
data.append(item.getId()).append("\r");
}
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.direction,
this.spacing,
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
@ -176,22 +176,37 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split("\t");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.direction = data.direction;
this.spacing = data.spacing;
this.setDelay(data.delay);
if (data.length == 4) {
try {
this.direction = Integer.valueOf(data[0]);
this.spacing = Integer.valueOf(data[1]);
this.setDelay(Integer.valueOf(data[2]));
} catch (Exception e) {
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (item != null)
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split("\t");
if (data.length == 4) {
try {
this.direction = Integer.parseInt(data[0]);
this.spacing = Integer.parseInt(data[1]);
this.setDelay(Integer.parseInt(data[2]));
} catch (Exception e) {
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -209,4 +224,18 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int direction;
int spacing;
int delay;
List<Integer> itemIds;
public JsonData(int direction, int spacing, int delay, List<Integer> itemIds) {
this.direction = direction;
this.spacing = spacing;
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -22,6 +22,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* Wired effect: move to closest user
@ -233,32 +234,41 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (this.items != null && !this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.parseInt(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
if (item != null)
this.items.add(item);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -342,4 +352,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -19,6 +19,8 @@ import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable {
@ -80,50 +82,61 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
@Override
public String getWiredData() {
THashSet<HabboItem> items = new THashSet<>(this.items.size() / 2);
THashSet<HabboItem> itemsToRemove = new THashSet<>(this.items.size() / 2);
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || (room != null && room.getHabboItem(item.getId()) == null))
items.add(item);
itemsToRemove.add(item);
}
for (HabboItem item : items) {
for (HabboItem item : itemsToRemove) {
this.items.remove(item);
}
StringBuilder data = new StringBuilder(this.direction + "\t" +
this.rotation + "\t" +
this.getDelay() + "\t");
for (HabboItem item : this.items) {
data.append(item.getId()).append("\r");
}
return data.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.direction,
this.rotation,
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split("\t");
if (data.length == 4) {
try {
this.direction = Integer.parseInt(data[0]);
this.rotation = Integer.parseInt(data[1]);
this.setDelay(Integer.parseInt(data[2]));
} catch (Exception e) {
System.out.println(e);
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.direction = data.direction;
this.rotation = data.rotation;
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split("\t");
if (data.length == 4) {
try {
this.direction = Integer.parseInt(data[0]);
this.rotation = Integer.parseInt(data[1]);
this.setDelay(Integer.parseInt(data[2]));
} catch (Exception e) {
System.out.println(e);
}
for (String s : data[3].split("\r")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -303,4 +316,18 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
public void cycle(Room room) {
this.itemCooldowns.clear();
}
}
static class JsonData {
int direction;
int rotation;
int delay;
List<Integer> itemIds;
public JsonData(int direction, int rotation, int delay, List<Integer> itemIds) {
this.direction = direction;
this.rotation = rotation;
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
@ -79,19 +80,32 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
@Override
public String getWiredData() {
return this.getDelay() + "\t" + this.length + "\t" + this.message;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.length,
this.message
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (data.length >= 3) {
try {
this.setDelay(Integer.valueOf(data[0]));
this.length = Integer.valueOf(data[1]);
this.message = data[2];
} catch (Exception e) {
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.length = data.length;
this.message = data.message;
} else {
String[] data = wiredData.split("\t");
if (data.length >= 3) {
try {
this.setDelay(Integer.valueOf(data[0]));
this.length = Integer.valueOf(data[1]);
this.message = data[2];
} catch (Exception e) {
}
}
}
}
@ -112,4 +126,16 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
static class JsonData {
int delay;
int length;
String message;
public JsonData(int delay, int length, String message) {
this.delay = delay;
this.length = length;
this.message = message;
}
}
}

View File

@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.threading.runnables.WiredResetTimers;
@ -85,17 +86,25 @@ public class WiredEffectResetTimers extends InteractionWiredEffect {
@Override
public String getWiredData() {
return this.delay + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.delay
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String data = set.getString("wired_data");
String wiredData = set.getString("wired_data");
try {
if (!data.equals(""))
this.delay = Integer.valueOf(data);
} catch (Exception e) {
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.delay = data.delay;
} else {
try {
if (!wiredData.equals("")) {
this.delay = Integer.parseInt(wiredData);
}
} catch (Exception e) {
}
}
this.setDelay(this.delay);
@ -111,4 +120,12 @@ public class WiredEffectResetTimers extends InteractionWiredEffect {
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
public JsonData(int delay) {
this.delay = delay;
}
}
}

View File

@ -26,6 +26,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectTeleport extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.TELEPORT;
@ -181,32 +182,40 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (this.items != null && !this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new ArrayList<>();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (item != null)
this.items.add(item);
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -232,4 +241,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
protected long requiredCooldown() {
return 50L;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -35,6 +35,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectToggleFurni extends InteractionWiredEffect {
private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectToggleFurni.class);
@ -193,7 +194,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
int state = 0;
if (!item.getExtradata().isEmpty()) {
try {
state = Integer.valueOf(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc.
state = Integer.parseInt(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc.
} catch (NumberFormatException ignored) {
}
@ -212,35 +213,48 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (this.items != null && !this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable)
continue;
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) {
continue;
}
if (item != null)
this.items.add(item);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable)
continue;
if (item != null)
this.items.add(item);
}
}
}
}
@ -256,4 +270,14 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -32,6 +32,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectToggleRandom extends InteractionWiredEffect {
private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectToggleRandom.class);
@ -192,35 +193,46 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (!this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
continue;
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
continue;
if (item != null)
this.items.add(item);
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (item != null)
this.items.add(item);
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
continue;
if (item != null)
this.items.add(item);
}
}
}
}
@ -236,4 +248,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
public WiredEffectType getType() {
return type;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -21,6 +21,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredEffectTriggerStacks extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.CALL_STACKS;
@ -156,32 +157,40 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
if (this.items != null && !this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String[] wiredData = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (item != null)
this.items.add(item);
if (wiredDataOld.length >= 1) {
this.setDelay(Integer.parseInt(wiredDataOld[0]));
}
if (wiredDataOld.length == 2) {
if (wiredDataOld[1].contains(";")) {
for (String s : wiredDataOld[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -202,4 +211,14 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
protected long requiredCooldown() {
return 250;
}
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
}

View File

@ -0,0 +1,11 @@
package com.eu.habbo.habbohotel.items.interactions.wired.interfaces;
import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting;
import gnu.trove.set.hash.THashSet;
public interface InteractionWiredMatchFurniSettings {
public THashSet<WiredMatchFurniSetting> getMatchFurniSettings();
public boolean shouldMatchState();
public boolean shouldMatchRotation();
public boolean shouldMatchPosition();
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -39,13 +40,22 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
@Override
public String getWiredData() {
return this.executeTime + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.executeTime
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
if (set.getString("wired_data").length() >= 1) {
this.executeTime = (Integer.valueOf(set.getString("wired_data")));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
this.executeTime = (Integer.parseInt(wiredData));
}
}
if (this.executeTime < 500) {
@ -115,4 +125,12 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
}
static class JsonData {
int executeTime;
public JsonData(int executeTime) {
this.executeTime = executeTime;
}
}
}

View File

@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -38,13 +39,22 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
@Override
public String getWiredData() {
return this.executeTime + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.executeTime
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
if (set.getString("wired_data").length() >= 1) {
this.executeTime = (Integer.valueOf(set.getString("wired_data")));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.executeTime = data.executeTime;
} else {
if (wiredData.length() >= 1) {
this.executeTime = (Integer.parseInt(wiredData));
}
}
if (this.executeTime < 500) {
@ -113,4 +123,12 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W
Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime);
}
static class JsonData {
int executeTime;
public JsonData(int executeTime) {
this.executeTime = executeTime;
}
}
}

View File

@ -21,6 +21,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
private static final Logger LOGGER = LoggerFactory.getLogger(WiredTriggerBotReachedFurni.class);
@ -124,38 +125,45 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.botName + ":");
if (!this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.botName,
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
String[] data = set.getString("wired_data").split(":");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.botName = data.botName;
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
if (data.length == 1) {
this.botName = data[0];
} else if (data.length == 2) {
this.botName = data[0];
if (data.length == 1) {
this.botName = data[0];
} else if (data.length == 2) {
this.botName = data[0];
String[] items = data[1].split(";");
String[] items = data[1].split(";");
for (int i = 0; i < items.length; i++) {
try {
HabboItem item = room.getHabboItem(Integer.valueOf(items[i]));
for (String id : items) {
try {
HabboItem item = room.getHabboItem(Integer.parseInt(id));
if (item != null)
this.items.add(item);
} catch (Exception e) {
LOGGER.error("Caught exception", e);
if (item != null)
this.items.add(item);
} catch (Exception e) {
LOGGER.error("Caught exception", e);
}
}
}
}
@ -166,4 +174,14 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
this.items.clear();
this.botName = "";
}
static class JsonData {
String botName;
List<Integer> itemIds;
public JsonData(String botName, List<Integer> itemIds) {
this.botName = botName;
this.itemIds = itemIds;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -62,12 +63,21 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
@Override
public String getWiredData() {
return this.botName;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.botName
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.botName = set.getString("wired_data");
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.botName = data.botName;
} else {
this.botName = wiredData;
}
}
@Override
@ -79,4 +89,12 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
String botName;
public JsonData(String botName) {
this.botName = botName;
}
}
}

View File

@ -16,12 +16,13 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED;
private THashSet<HabboItem> items;
private String message = "";
public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -55,34 +56,35 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
if (this.items != null) {
if (!this.items.isEmpty()) {
for (HabboItem item : this.items) {
wiredData.append(item.getId()).append(";");
}
} else
wiredData.append("\t");
}
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
String wiredData = set.getString("wired_data");
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
this.message = wiredData.split(":")[1];
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.parseInt(wiredData.split(":")[0]));
if (item != null)
this.items.add(item);
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
}
}
}
@ -91,7 +93,6 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
@Override
public void onPickUp() {
this.items.clear();
this.message = "";
}
@Override
@ -126,7 +127,7 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
}
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.message);
message.appendString("");
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
@ -153,4 +154,12 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -41,12 +42,21 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
@Override
public String getWiredData() {
return this.username;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.username
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.username = set.getString("wired_data");
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.username = data.username;
} else {
this.username = wiredData;
}
}
@Override
@ -86,4 +96,12 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
String username;
public JsonData(String username) {
this.username = username;
}
}
}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -41,16 +42,27 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
@Override
public String getWiredData() {
return (this.ownerOnly ? "1" : "0") + "\t" + this.key;
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.ownerOnly,
this.key
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
String[] data = set.getString("wired_data").split("\t");
String wiredData = set.getString("wired_data");
if (data.length == 2) {
this.ownerOnly = data[0].equalsIgnoreCase("1");
this.key = data[1];
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.ownerOnly = data.ownerOnly;
this.key = data.key;
} else {
String[] data = wiredData.split("\t");
if (data.length == 2) {
this.ownerOnly = data[0].equalsIgnoreCase("1");
this.key = data[1];
}
}
}
@ -93,4 +105,14 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
boolean ownerOnly;
String key;
public JsonData(boolean ownerOnly, String key) {
this.ownerOnly = ownerOnly;
this.key = key;
}
}
}

View File

@ -14,14 +14,13 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_OFF_FURNI;
private THashSet<HabboItem> items;
private String message = "";
public WiredTriggerHabboWalkOffFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -45,55 +44,49 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
if (!this.items.isEmpty()) {
List<HabboItem> toRemove = new ArrayList<>(0);
for (HabboItem item : this.items) {
if (item.getRoomId() == this.getRoomId()) {
wiredData.append(item.getId()).append(";");
} else {
toRemove.add(item);
}
}
this.items.removeAll(toRemove);
} else
wiredData.append("\t");
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new WiredTriggerFurniStateToggled.JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
this.message = wiredData.split(":")[1];
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.parseInt(wiredData.split(":")[0]));
try {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
if (item != null)
this.items.add(item);
} catch (Exception e) {
try {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
} catch (Exception e) {
}
}
}
}
}
}
@Override
public void onPickUp() {
this.items.clear();
this.message = "";
}
@Override
@ -126,7 +119,7 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
}
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.message);
message.appendString("");
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
@ -154,4 +147,12 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -16,12 +16,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
public static final WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
private THashSet<HabboItem> items;
private String message = "";
public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@ -73,7 +73,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
}
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString(this.message);
message.appendString("");
message.appendInt(0);
message.appendInt(0);
message.appendInt(this.getType().code);
@ -99,44 +99,40 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
@Override
public String getWiredData() {
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
if (!this.items.isEmpty()) {
List<HabboItem> toRemove = new ArrayList<>(0);
for (HabboItem item : this.items) {
if (item.getRoomId() == this.getRoomId()) {
wiredData.append(item.getId()).append(";");
} else {
toRemove.add(item);
}
}
this.items.removeAll(toRemove);
} else
wiredData.append("\t");
return wiredData.toString();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items.clear();
String wiredData = set.getString("wired_data");
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
this.message = wiredData.split(":")[1];
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
for (Integer id: data.itemIds) {
HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
if (wiredData.split(":").length >= 3) {
super.setDelay(Integer.parseInt(wiredData.split(":")[0]));
try {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
if (!wiredData.split(":")[2].equals("\t")) {
for (String s : wiredData.split(":")[2].split(";")) {
if (s.isEmpty())
continue;
if (item != null)
this.items.add(item);
} catch (Exception e) {
try {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
} catch (Exception e) {
}
}
}
}
@ -146,11 +142,18 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
@Override
public void onPickUp() {
this.items.clear();
this.message = "";
}
@Override
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
}

View File

@ -41,13 +41,22 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
@Override
public String getWiredData() {
return this.repeatTime + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.repeatTime
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
if (set.getString("wired_data").length() >= 1) {
this.repeatTime = (Integer.valueOf(set.getString("wired_data")));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
this.repeatTime = (Integer.valueOf(wiredData));
}
}
if (this.repeatTime < 500) {
@ -136,4 +145,12 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy
}
}
}
static class JsonData {
int repeatTime;
public JsonData(int repeatTime) {
this.repeatTime = repeatTime;
}
}
}

View File

@ -40,13 +40,22 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
@Override
public String getWiredData() {
return this.repeatTime + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.repeatTime
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
if (set.getString("wired_data").length() >= 1) {
this.repeatTime = (Integer.valueOf(set.getString("wired_data")));
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.repeatTime = data.repeatTime;
} else {
if (wiredData.length() >= 1) {
this.repeatTime = (Integer.valueOf(wiredData));
}
}
if (this.repeatTime < 5000) {
@ -130,4 +139,12 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements
}
}
}
static class JsonData {
int repeatTime;
public JsonData(int repeatTime) {
this.repeatTime = repeatTime;
}
}
}

View File

@ -4,6 +4,7 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
@ -37,14 +38,23 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
@Override
public String getWiredData() {
return this.score + "";
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.score
));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
try {
this.score = Integer.valueOf(set.getString("wired_data"));
} catch (Exception e) {
String wiredData = set.getString("wired_data");
if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.score = data.score;
} else {
try {
this.score = Integer.parseInt(wiredData);
} catch (Exception e) {
}
}
}
@ -85,4 +95,12 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger {
public boolean isTriggeredByRoomUnit() {
return true;
}
static class JsonData {
int score;
public JsonData(int score) {
this.score = score;
}
}
}

View File

@ -428,6 +428,16 @@ public class ModToolManager {
return bans;
}
//if machine id is empty, downgrade ban type to IP ban
if( (type == ModToolBanType.MACHINE || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getMachineID().isEmpty())) {
type = ModToolBanType.IP;
}
//if ip address is empty, downgrade ban type to account ban
if( (type == ModToolBanType.IP || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getIpLogin().isEmpty())) {
type = ModToolBanType.ACCOUNT;
}
ModToolBan ban = new ModToolBan(targetUserId, offlineInfo != null ? offlineInfo.getIpLogin() : "offline", offlineInfo != null ? offlineInfo.getMachineID() : "offline", moderator.getHabboInfo().getId(), Emulator.getIntUnixTimestamp() + duration, reason, type, cfhTopic);
Emulator.getPluginManager().fireEvent(new SupportUserBannedEvent(moderator, target, ban));
Emulator.getThreading().run(ban);
@ -505,6 +515,7 @@ public class ModToolManager {
return ban;
}
@Deprecated
public boolean hasIPBan(Channel habbo) {
if (habbo == null)
return false;
@ -512,9 +523,13 @@ public class ModToolManager {
if (habbo.remoteAddress() == null || ((InetSocketAddress) habbo.remoteAddress()).getAddress() == null)
return false;
return this.hasIPBan(((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress());
}
public boolean hasIPBan(String ipAddress) {
boolean banned = false;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM bans WHERE ip = ? AND (type = 'ip' OR type = 'super') AND ban_expire > ? LIMIT 1")) {
statement.setString(1, ((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress());
statement.setString(1, ipAddress);
statement.setInt(2, Emulator.getIntUnixTimestamp());
try (ResultSet set = statement.executeQuery()) {
@ -525,7 +540,6 @@ public class ModToolManager {
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
return banned;
}

View File

@ -383,6 +383,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.updateItem(item);
}
}
for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) {
item.setExtradata("1");
this.updateItem(item);
}
}
Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this));
@ -1205,8 +1210,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
habbo.getRoomUnit().increaseIdleTimer();
if (habbo.getRoomUnit().isIdle()) {
this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo});
boolean danceIsNone = (habbo.getRoomUnit().getDanceType() == DanceType.NONE);
if (danceIsNone)
this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose());
if (danceIsNone && !Emulator.getConfig().getBoolean("hotel.roomuser.idle.not_dancing.ignore.wired_idle"))
WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo});
}
} else {
habbo.getRoomUnit().increaseIdleTimer();
@ -2424,7 +2432,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionSnowboardSlope) {
this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionFireworks) {
this.roomSpecialTypes.addUndefined(item);
}
}
}

View File

@ -14,8 +14,10 @@ import com.eu.habbo.messages.outgoing.rooms.FloodCounterComposer;
import com.eu.habbo.messages.outgoing.rooms.ForwardToRoomComposer;
import com.eu.habbo.messages.outgoing.rooms.users.*;
import com.eu.habbo.messages.outgoing.users.*;
import com.eu.habbo.plugin.events.furniture.FurnitureBuildheightEvent;
import com.eu.habbo.plugin.events.users.UserCreditsEvent;
import com.eu.habbo.plugin.events.users.UserDisconnectEvent;
import com.eu.habbo.plugin.events.users.UserGetIPAddressEvent;
import com.eu.habbo.plugin.events.users.UserPointsEvent;
import gnu.trove.TIntCollection;
import gnu.trove.map.hash.THashMap;
@ -114,11 +116,31 @@ public class Habbo implements Runnable {
}
public void connect() {
public boolean connect() {
String ip = "";
if (!Emulator.getConfig().getBoolean("networking.tcp.proxy") && this.client.getChannel().remoteAddress() != null) {
SocketAddress address = this.client.getChannel().remoteAddress();
ip = ((InetSocketAddress) address).getAddress().getHostAddress();
}
if (address != null) this.habboInfo.setIpLogin(((InetSocketAddress) address).getAddress().getHostAddress());
if (Emulator.getPluginManager().isRegistered(UserGetIPAddressEvent.class, true)) {
UserGetIPAddressEvent event = Emulator.getPluginManager().fireEvent(new UserGetIPAddressEvent(this, ip));
if (event.hasChangedIP()) {
ip = event.getUpdatedIp();
}
}
if (!ip.isEmpty()) {
this.habboInfo.setIpLogin(ip);
}
if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) {
return false;
}
if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.habboInfo.getIpLogin())) {
return false;
}
this.habboInfo.setMachineID(this.client.getMachineId());
@ -128,6 +150,7 @@ public class Habbo implements Runnable {
Emulator.getGameEnvironment().getRoomManager().loadRoomsForHabbo(this);
LOGGER.info("{} logged in from IP {}", this.habboInfo.getUsername(), this.habboInfo.getIpLogin());
return true;
}

View File

@ -205,7 +205,7 @@ public class HabboManager {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE ip_register = ? OR ip_current = ? AND id != ? ORDER BY id DESC LIMIT ?")) {
statement.setString(1, habbo.getHabboInfo().getIpRegister());
statement.setString(2, habbo.getClient().getChannel().remoteAddress().toString());
statement.setString(2, habbo.getHabboInfo().getIpLogin());
statement.setInt(3, habbo.getHabboInfo().getId());
statement.setInt(4, limit);

View File

@ -64,6 +64,7 @@ import com.eu.habbo.messages.incoming.trading.*;
import com.eu.habbo.messages.incoming.unknown.RequestResolutionEvent;
import com.eu.habbo.messages.incoming.unknown.UnknownEvent1;
import com.eu.habbo.messages.incoming.users.*;
import com.eu.habbo.messages.incoming.wired.WiredApplySetConditionsEvent;
import com.eu.habbo.messages.incoming.wired.WiredConditionSaveDataEvent;
import com.eu.habbo.messages.incoming.wired.WiredEffectSaveDataEvent;
import com.eu.habbo.messages.incoming.wired.WiredTriggerSaveDataEvent;
@ -579,6 +580,7 @@ public class PacketManager {
this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class);
this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class);
this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class);
this.registerHandler(Incoming.WiredApplySetConditionsEvent, WiredApplySetConditionsEvent.class);
}
void registerUnknown() throws Exception {

View File

@ -155,6 +155,7 @@ public class Incoming {
public static final int RequestInventoryItemsEvent = 3150;
public static final int ModToolRoomAlertEvent = 3842;
public static final int WiredEffectSaveDataEvent = 2281;
public static final int WiredApplySetConditionsEvent = 3373;
public static final int CheckPetNameEvent = 2109;
public static final int SecureLoginEvent = 2419;
public static final int BotSaveSettingsEvent = 2624;

View File

@ -336,7 +336,10 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler {
return;
}
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver"));
if (this.client.getHabbo().getHabboInfo().getId() != userId) {
AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver"));
}
if (habbo != null) {
habbo.getClient().sendResponse(new AddHabboItemComposer(gift));
habbo.getClient().getHabbo().getInventory().getItemsComponent().addItem(gift);
@ -351,7 +354,9 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler {
habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys));
}
AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver"));
if (this.client.getHabbo().getHabboInfo().getId() != userId) {
AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver"));
}
if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) {
if (totalCredits > 0) {

View File

@ -21,7 +21,7 @@ import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer;
import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer;
import com.eu.habbo.messages.outgoing.handshake.DebugConsoleComposer;
import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer;
import com.eu.habbo.messages.outgoing.handshake.SessionRightsComposer;
import com.eu.habbo.messages.outgoing.handshake.AvailabilityStatusMessageComposer;
import com.eu.habbo.messages.outgoing.handshake.PingComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryAchievementsComposer;
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
@ -57,8 +57,9 @@ public class SecureLoginEvent extends MessageHandler {
if (!Emulator.isReady)
return;
if (Emulator.getCrypto().isEnabled() && !this.client.isHandshakeFinished()) {
if (Emulator.getConfig().getBoolean("encryption.forced", false) && Emulator.getCrypto().isEnabled() && !this.client.isHandshakeFinished()) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
LOGGER.warn("Encryption is forced and TLS Handshake isn't finished! Closed connection...");
return;
}
@ -66,30 +67,26 @@ public class SecureLoginEvent extends MessageHandler {
if (Emulator.getPluginManager().fireEvent(new SSOAuthenticationEvent(sso)).isCancelled()) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
LOGGER.info("SSO Authentication is cancelled by a plugin. Closed connection...");
return;
}
if (sso.isEmpty()) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
LOGGER.warn("Client is trying to connect without SSO ticket! Closed connection...");
return;
}
if (this.client.getHabbo() == null) {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso);
if (habbo != null) {
if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
return;
}
if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.client.getChannel())) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
return;
}
try {
habbo.setClient(this.client);
this.client.setHabbo(habbo);
this.client.getHabbo().connect();
if(!this.client.getHabbo().connect()) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
return;
}
if (this.client.getHabbo().getHabboInfo() == null) {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
@ -123,7 +120,7 @@ public class SecureLoginEvent extends MessageHandler {
messages.add(new UserClothesComposer(this.client.getHabbo()).compose());
messages.add(new NewUserIdentityComposer(habbo).compose());
messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose());
messages.add(new SessionRightsComposer().compose());
messages.add(new AvailabilityStatusMessageComposer(true, false, true).compose());
messages.add(new PingComposer().compose());
messages.add(new DebugConsoleComposer(Emulator.debugging).compose());
messages.add(new UserAchievementScoreComposer(this.client.getHabbo()).compose());
@ -191,7 +188,7 @@ public class SecureLoginEvent extends MessageHandler {
}
}
Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress()));
Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getHabbo().getHabboInfo().getIpLogin()));
if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) {
final Habbo finalHabbo = habbo;
@ -222,6 +219,7 @@ public class SecureLoginEvent extends MessageHandler {
}
} else {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);
LOGGER.warn("Someone tried to login with a non-existing SSO token! Closed connection...");
}
} else {
Emulator.getGameServer().getGameClientManager().disposeClient(this.client);

View File

@ -1,89 +0,0 @@
package com.eu.habbo.messages.incoming.handshake;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.friends.FriendsComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer;
import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer;
import com.eu.habbo.messages.outgoing.handshake.DebugConsoleComposer;
import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer;
import com.eu.habbo.messages.outgoing.handshake.SessionRightsComposer;
import com.eu.habbo.messages.outgoing.modtool.ModToolComposer;
import com.eu.habbo.messages.outgoing.navigator.*;
import com.eu.habbo.messages.outgoing.users.*;
import com.eu.habbo.plugin.events.users.UserLoginEvent;
import java.util.ArrayList;
public class SecureLoginEvent_BACKUP extends MessageHandler {
@Override
public void handle() throws Exception {
if (!Emulator.isReady)
return;
String sso = this.packet.readString();
if (this.client.getHabbo() == null) {
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso);
if (habbo != null) {
habbo.setClient(this.client);
this.client.setHabbo(habbo);
this.client.getHabbo().connect();
//this.client.sendResponse(new DebugConsoleComposer());
Emulator.getThreading().run(habbo);
Emulator.getGameEnvironment().getHabboManager().addHabbo(habbo);
ArrayList<ServerMessage> messages = new ArrayList<>();
messages.add(new SecureLoginOKComposer().compose());
messages.add(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), 0).compose());
messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose());
messages.add(new UserClubComposer(this.client.getHabbo()).compose());
messages.add(new DebugConsoleComposer(Emulator.debugging).compose());
messages.add(new UserAchievementScoreComposer(this.client.getHabbo()).compose());
messages.add(new NewUserIdentityComposer(habbo).compose());
messages.add(new UserPerksComposer(habbo).compose());
messages.add(new SessionRightsComposer().compose());
messages.add(new FavoriteRoomsCountComposer(habbo).compose());
//messages.add(new FriendsComposer(this.client.getHabbo()).compose());
//messages.add(new NewUserIdentityComposer().compose());
//messages.add(new UserDataComposer(this.client.getHabbo()).compose());
//messages.add(new SessionRightsComposer().compose());
//messages.add(new MinimailCountComposer().compose());
//messages.add(new MessengerInitComposer(this.client.getHabbo()).compose());
//messages.add(new FriendsComposer(this.client.getHabbo()).compose());
if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) {
messages.add(new ModToolComposer(this.client.getHabbo()).compose());
}
this.client.sendResponses(messages);
//Hardcoded
this.client.sendResponse(new NewNavigatorMetaDataComposer());
this.client.sendResponse(new NewNavigatorLiftedRoomsComposer());
this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer());
this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches()));
this.client.sendResponse(new NewNavigatorEventCategoriesComposer());
//this.client.sendResponse(new HotelViewComposer());
//this.client.sendResponse(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), this.client.getHabbo().getHabboInfo().getHomeRoom()));
//this.client.sendResponse(new UserEffectsListComposer());
Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress()));
} else {
this.client.sendResponse(new GenericAlertComposer("Can't connect *sadpanda*"));
this.client.getChannel().close();
}
}
}
}

View File

@ -2,15 +2,17 @@ package com.eu.habbo.messages.incoming.rooms.items;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler;
public class MannequinSaveLookEvent extends MessageHandler {
@Override
public void handle() throws Exception {
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
Habbo habbo = this.client.getHabbo();
Room room = habbo.getHabboInfo().getCurrentRoom();
if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId())
if (room == null || !room.isOwner(habbo))
return;
HabboItem item = room.getHabboItem(this.packet.readInt());
@ -22,7 +24,7 @@ public class MannequinSaveLookEvent extends MessageHandler {
StringBuilder look = new StringBuilder();
for (String s : this.client.getHabbo().getHabboInfo().getLook().split("\\.")) {
for (String s : habbo.getHabboInfo().getLook().split("\\.")) {
if (!s.contains("hr") && !s.contains("hd") && !s.contains("he") && !s.contains("ea") && !s.contains("ha") && !s.contains("fa")) {
look.append(s).append(".");
}
@ -33,9 +35,9 @@ public class MannequinSaveLookEvent extends MessageHandler {
}
if (data.length == 3) {
item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]);
item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]);
} else {
item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + this.client.getHabbo().getHabboInfo().getUsername() + "'s look.");
item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + habbo.getHabboInfo().getUsername() + "'s look.");
}
item.needsUpdate(true);

View File

@ -9,7 +9,7 @@ public class MannequinSaveNameEvent extends MessageHandler {
@Override
public void handle() throws Exception {
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId())
if (room == null || !room.isOwner(this.client.getHabbo()))
return;
HabboItem item = room.getHabboItem(this.packet.readInt());

View File

@ -0,0 +1,103 @@
package com.eu.habbo.messages.incoming.wired;
import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings;
import com.eu.habbo.habbohotel.rooms.FurnitureMovementError;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomTileState;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class WiredApplySetConditionsEvent extends MessageHandler {
@Override
public int getRatelimit() {
return 500;
}
@Override
public void handle() throws Exception {
int itemId = this.packet.readInt();
// Executing Habbo has to be in a Room
if (!this.client.getHabbo().getRoomUnit().isInRoom()) {
this.client.sendResponse(new BubbleAlertComposer(
BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key,
FurnitureMovementError.NO_RIGHTS.errorCode
));
return;
}
Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom();
if (room != null) {
// Executing Habbo should be able to edit wireds
if (room.hasRights(this.client.getHabbo()) || room.isOwner(this.client.getHabbo())) {
List<HabboItem> wireds = new ArrayList<>();
wireds.addAll(room.getRoomSpecialTypes().getConditions());
wireds.addAll(room.getRoomSpecialTypes().getEffects());
// Find the item with the given ID in the room
Optional<HabboItem> item = wireds.stream()
.filter(wired -> wired.getId() == itemId)
.findFirst();
// If the item exists
if (item.isPresent()) {
HabboItem wiredItem = item.get();
// The item should have settings to match furni state, position and rotation
if (wiredItem instanceof InteractionWiredMatchFurniSettings) {
InteractionWiredMatchFurniSettings wired = (InteractionWiredMatchFurniSettings) wiredItem;
// Try to apply the set settings to each item
wired.getMatchFurniSettings().forEach(setting -> {
HabboItem matchItem = room.getHabboItem(setting.item_id);
// Match state
if (wired.shouldMatchState() && matchItem.allowWiredResetState()) {
if (!setting.state.equals(" ") && !matchItem.getExtradata().equals(setting.state)) {
matchItem.setExtradata(setting.state);
room.updateItemState(matchItem);
}
}
RoomTile oldLocation = room.getLayout().getTile(matchItem.getX(), matchItem.getY());
double oldZ = matchItem.getZ();
// Match Position & Rotation
if(wired.shouldMatchRotation() && !wired.shouldMatchPosition()) {
if(matchItem.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, matchItem, setting.rotation, false) == FurnitureMovementError.NONE) {
room.moveFurniTo(matchItem, oldLocation, setting.rotation, null, true);
}
}
else if(wired.shouldMatchPosition()) {
boolean slideAnimation = !wired.shouldMatchRotation() || matchItem.getRotation() == setting.rotation;
RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y);
int newRotation = wired.shouldMatchRotation() ? setting.rotation : matchItem.getRotation();
if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) && room.furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE) {
if(room.moveFurniTo(matchItem, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
if(slideAnimation) {
room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getZ(), 0, room).compose());
}
}
}
}
});
}
}
}
}
}
}

View File

@ -84,7 +84,7 @@ public class Outgoing {
public final static int RoomScoreComposer = 482;
public final static int DoorbellAddUserComposer = 2309;
public final static int SecureLoginOKComposer = 2491;
public final static int SessionRightsComposer = 2033;
public final static int AvailabilityStatusMessageComposer = 2033;
public final static int GuildMemberUpdateComposer = 265;
public final static int RoomFloorItemsComposer = 1778;
public final static int InventoryItemsComposer = 994;

View File

@ -0,0 +1,27 @@
package com.eu.habbo.messages.outgoing.handshake;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class AvailabilityStatusMessageComposer extends MessageComposer {
private final boolean isOpen;
private final boolean isShuttingDown;
private final boolean isAuthenticHabbo;
public AvailabilityStatusMessageComposer(boolean isOpen, boolean isShuttingDown, boolean isAuthenticHabbo) {
this.isOpen = isOpen;
this.isShuttingDown = isShuttingDown;
this.isAuthenticHabbo = isAuthenticHabbo;
}
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.AvailabilityStatusMessageComposer);
this.response.appendBoolean(isOpen);//isOpen
this.response.appendBoolean(isShuttingDown);//onShutdown
this.response.appendBoolean(isAuthenticHabbo);//isAuthenticHabbo
return this.response;
}
}

View File

@ -1,20 +0,0 @@
package com.eu.habbo.messages.outgoing.handshake;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class SessionRightsComposer extends MessageComposer {
private static final boolean unknownBooleanOne = true; //true
private static final boolean unknownBooleanTwo = false;
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.SessionRightsComposer);
this.response.appendBoolean(unknownBooleanOne);
this.response.appendBoolean(true);
this.response.appendBoolean(true);
return this.response;
}
}

View File

@ -59,13 +59,13 @@ public class GameMessageHandler extends ChannelInboundHandlerAdapter {
ctx.channel().close();
return;
}
if (cause instanceof TooLongFrameException) {
LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\".");
} else {
LOGGER.error("Disconnecting client, exception in GameMessageHander.", cause);
if (Emulator.getConfig().getBoolean("debug.mode")) {
if (cause instanceof TooLongFrameException) {
LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\".");
} else {
LOGGER.error("Disconnecting client, exception in GameMessageHander.", cause);
}
}
ctx.channel().close();
}

View File

@ -0,0 +1,28 @@
package com.eu.habbo.plugin.events.users;
import com.eu.habbo.habbohotel.users.Habbo;
public class UserGetIPAddressEvent extends UserEvent{
public final String oldIp;
private String updatedIp;
private boolean changedIP = false;
public UserGetIPAddressEvent(Habbo habbo, String ip) {
super(habbo);
this.oldIp = ip;
}
public void setUpdatedIp(String updatedIp) {
this.updatedIp = updatedIp;
this.changedIP = true;
}
public boolean hasChangedIP() {
return changedIP;
}
public String getUpdatedIp() {
return updatedIp;
}
}

View File

@ -6,10 +6,9 @@ import java.net.SocketAddress;
public class UserLoginEvent extends UserEvent {
public final SocketAddress ip;
public final String ip;
public UserLoginEvent(Habbo habbo, SocketAddress ip) {
public UserLoginEvent(Habbo habbo, String ip) {
super(habbo);
this.ip = ip;

View File

@ -42,17 +42,15 @@ public class RoomUnitWalkToRoomUnit implements Runnable {
if (this.goalTile == null) {
this.findNewLocation();
Emulator.getThreading().run(this, 500);
}
if (this.goalTile == null)
return;
}
if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal
if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) {
for (Runnable r : this.targetReached) {
Emulator.getThreading().run(r);
WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{this.walker});
WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{ this.walker });
}
} else {
Emulator.getThreading().run(this, 500);

View File

@ -0,0 +1,46 @@
package com.eu.habbo.threading.runnables.games;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
public class GameTimer implements Runnable {
private final InteractionGameTimer timer;
public GameTimer(InteractionGameTimer timer) {
this.timer = timer;
}
@Override
public void run() {
if (timer.getRoomId() == 0) {
timer.setRunning(false);
return;
}
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(timer.getRoomId());
if (room == null || !timer.isRunning() || timer.isPaused()) {
timer.setThreadActive(false);
return;
}
timer.reduceTime();
if (timer.getTimeNow() < 0) timer.setTimeNow(0);
if (timer.getTimeNow() > 0) {
timer.setThreadActive(true);
Emulator.getThreading().run(this, 1000);
} else {
timer.setThreadActive(false);
timer.setTimeNow(0);
timer.endGame(room);
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
}
room.updateItem(timer);
}
}