diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..e045ce45
--- /dev/null
+++ b/Dockerfile
@@ -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"]
diff --git a/README.md b/README.md
index 364c2985..bff62d04 100644
--- a/README.md
+++ b/README.md
@@ -11,10 +11,11 @@ TheGeneral's own words were "dont like it then dont use it". We did not like wha
Arcturus Morningstar is released under the [GNU General Public License v3](https://www.gnu.org/licenses/gpl-3.0.txt).
## Versions ##
-![image](https://img.shields.io/badge/VERSION-2.4.0-success.svg?style=for-the-badge&logo=appveyor)
-![image](https://img.shields.io/badge/STATUS-STABLE-blue.svg?style=for-the-badge&logo=appveyor)
+[![image](https://img.shields.io/badge/VERSION-3.0.0-success.svg?style=for-the-badge&logo=appveyor)](#)
+[![image](https://img.shields.io/badge/STATUS-STABLE-blue.svg?style=for-the-badge&logo=appveyor)](#)
+[![image](https://img.shields.io/discord/557240155040251905?style=for-the-badge&logo=discord&color=7289DA&label=DISCORD&logoColor=fff)](https://discord.gg/BzfFsTp)
-Compiled Download: https://git.krews.org/morningstar/Arcturus-Community/releases
+Compiled Download: https://git.krews.org/morningstar/Arcturus-Community/-/releases
Client build: **PRODUCTION-201611291003-338511768**
@@ -24,17 +25,36 @@ When making an bug report or a feature request use the template we provide so th
## Credits ##
- TheGeneral
-- Capheus (Decompilation.)
-- Harmonic
- Beny
-- Claudio
- Alejandro
-- Harmony
-- Quadral (Pathfinder)
+- Capheus
- Skeletor
-- z
-- ArpyAge
+- Harmonic
- Mike
+- Remco
+- zGrav
+- Quadral
+- Harmony
+- Swirny
+- ArpyAge
+- Mikkel
+- Rodolfo
+- Rasmus
+- Kitt Mustang
+- Snaiker
+- nttzx
+- necmi
+- Dome
+- Jose Flores
+- Cam
+- Oliver
+- Narzo
+- Tenshie
+- MartenM
+- Ridge
+- SenpaiDipper
+- Snaiker
+- Thijmen
## Discord ##
diff --git a/pom.xml b/pom.xml
index 35de71dc..419c9bea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.eu.habbo
Habbo
- 2.4.0
+ 3.0.0
UTF-8
diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql
new file mode 100644
index 00000000..70294fbb
--- /dev/null
+++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql
@@ -0,0 +1,132 @@
+CREATE TABLE `users_subscriptions` (
+ `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `user_id` int(10) UNSIGNED NULL,
+ `subscription_type` varchar(255) NULL,
+ `timestamp_start` int(10) UNSIGNED NULL,
+ `duration` int(10) UNSIGNED NULL,
+ `active` tinyint(1) NULL DEFAULT 1,
+ PRIMARY KEY (`id`),
+ INDEX `user_id`(`user_id`),
+ INDEX `subscription_type`(`subscription_type`),
+ INDEX `timestamp_start`(`timestamp_start`),
+ INDEX `active`(`active`)
+);
+
+CREATE TABLE `logs_shop_purchases` (
+ `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `timestamp` int(10) UNSIGNED NULL,
+ `user_id` int(10) UNSIGNED NULL,
+ `catalog_item_id` int(10) UNSIGNED NULL,
+ `item_ids` text DEFAULT NULL,
+ `catalog_name` varchar(255) NULL,
+ `cost_credits` int(10) NULL,
+ `cost_points` int(10) NULL,
+ `points_type` int(10) NULL,
+ `amount` int(10) NULL,
+ PRIMARY KEY (`id`),
+ INDEX `timestamp`(`timestamp`),
+ INDEX `user_id`(`user_id`)
+);
+
+CREATE TABLE `logs_hc_payday` (
+ `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `timestamp` int(10) UNSIGNED NULL,
+ `user_id` int(10) UNSIGNED NULL,
+ `hc_streak` int(10) UNSIGNED NULL,
+ `total_coins_spent` int(10) UNSIGNED NULL,
+ `reward_coins_spent` int(10) UNSIGNED NULL,
+ `reward_streak` int(10) UNSIGNED NULL,
+ `total_payout` int(10) UNSIGNED NULL,
+ `currency` varchar(255) NULL,
+ `claimed` tinyint(1) DEFAULT 0 NULL,
+ PRIMARY KEY (`id`),
+ INDEX `timestamp`(`timestamp`),
+ INDEX `user_id`(`user_id`)
+);
+
+ALTER TABLE `emulator_settings` MODIFY COLUMN `value` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL AFTER `key`;
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.enabled', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.next_date', '2020-10-15 00:00:00');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.interval', '1 month');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.query', 'SELECT SUM(cost_credits) AS `amount_spent` FROM `logs_shop_purchases` WHERE `user_id` = @user_id AND `timestamp` > @timestamp_start AND `timestamp` <= @timestamp_end AND `catalog_name` NOT LIKE \'CF_%\' AND `catalog_name` NOT LIKE \'CFC_%\';');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.streak', '7=5;30=10;60=15;90=20;180=25;365=30');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.currency', 'credits');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.percentage', '10');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.payday.creditsspent_reset_on_expire', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.achievement', 'VipHC');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.discount.enabled', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.hc.discount.days_before_end', '7');
+
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.scheduler.enabled', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('subscriptions.scheduler.interval', '10');
+
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onhcexpired', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onlogin', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onchangelooks', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onmimic', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onmannequin', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.clothingvalidation.onfballgate', '0');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('gamedata.figuredata.url', 'https://habbo.com/gamedata/figuredata/0');
+
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.max.friends', '300');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.max.friends.hc', '1100');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.max.rooms', '50');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.users.max.rooms.hc', '75');
+
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.pixels.hc_modifier', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.points.hc_modifier', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.credits.hc_modifier', '1');
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('hotel.auto.gotwpoints.hc_modifier', '1');
+
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('room.chat.mutearea.allow_whisper', '1');
+
+DELETE FROM `emulator_settings` WHERE `key` IN ('hotel.max.rooms.per.user', 'hotel.max.rooms.user', 'hotel.max.rooms.vip', 'max.friends', 'hotel.max.friends', 'max.friends.hc', 'hotel.max.friends.hc');
+
+ALTER TABLE `users_settings` ADD COLUMN `max_friends` int(10) NULL DEFAULT 300 AFTER `has_gotten_default_saved_searches`;
+ALTER TABLE `users_settings` ADD COLUMN `max_rooms` int(10) NULL DEFAULT 50 AFTER `has_gotten_default_saved_searches`;
+ALTER TABLE `users_settings` ADD COLUMN `last_hc_payday` int(10) NULL DEFAULT 0 AFTER `has_gotten_default_saved_searches`;
+ALTER TABLE `users_settings` ADD COLUMN `hc_gifts_claimed` int(10) NULL DEFAULT 0 AFTER `has_gotten_default_saved_searches`;
+
+ALTER TABLE `permissions` ADD COLUMN `cmd_subscription` enum('0','1') NULL DEFAULT '0' AFTER `cmd_credits`;
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_subscription', 'subscription;sub');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.invalid_action', 'Invalid action specified. Must be add, +, remove or -');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.type_not_found', '%subscription% is not a valid subscription type');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.invalid_params_time', 'Invalid time span, try: x minutes/days/weeks/months');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.success_add_time', 'Successfully added %time% seconds to %subscription% on %user%');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.user_not_have', '%user% does not have the %subscription% subscription');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.success_remove_time', 'Successfully removed %time% seconds from %subscription% on %user%');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.success_remove_sub', 'Successfully removed %subscription% sub from %user%');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.user_not_found', '%user% was not found');
+INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscription.invalid_params', 'Invalid command format');
+
+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();
+
+INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.rooms.deco_hosting', '1');
+
+INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('easter_eggs.enabled', '1');
+
+ALTER TABLE `bots`
+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 ');
+
+-- Making items.wired_data column bigger since wired data is saved as JSON now
+ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000);
+
+-- Mute area sqls
+INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('room.chat.mutearea.allow_whisper', 'false');
+
+
diff --git a/sqlupdates/2_4_0-RC-2 to 2_4_0-RC-3.sql b/sqlupdates/2_4_0-RC-2 to 2_4_0-RC-3.sql
new file mode 100644
index 00000000..4e5a5206
--- /dev/null
+++ b/sqlupdates/2_4_0-RC-2 to 2_4_0-RC-3.sql
@@ -0,0 +1,2 @@
+-- Recycler value fix
+INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('recycler.value', '8');
diff --git a/sqlupdates/3_0_BETA_1 to 3_0_0.sql b/sqlupdates/3_0_BETA_1 to 3_0_0.sql
new file mode 100644
index 00000000..31e6474c
--- /dev/null
+++ b/sqlupdates/3_0_BETA_1 to 3_0_0.sql
@@ -0,0 +1,9 @@
+-- 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%');
+
+-- Enable bubble alerts
+INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('bubblealerts.enabled', '1');
diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java
index 9954c318..33a46886 100644
--- a/src/main/java/com/eu/habbo/Emulator.java
+++ b/src/main/java/com/eu/habbo/Emulator.java
@@ -24,10 +24,10 @@ import java.io.*;
import java.security.MessageDigest;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Random;
+import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public final class Emulator {
@@ -35,13 +35,12 @@ public final class Emulator {
private static final String OS_NAME = System.getProperty("os.name");
private static final String CLASS_PATH = System.getProperty("java.class.path");
- public final static int MAJOR = 2;
- public final static int MINOR = 4;
+ public final static int MAJOR = 3;
+ public final static int MINOR = 0;
public final static int BUILD = 0;
-
public final static String PREVIEW = "";
- public static final String version = "Arcturus Morningstar" + " " + MAJOR + "." + MINOR + "." + BUILD;
+ public static final String version = "Arcturus Morningstar" + " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW;
private static final String logo =
"\n" +
"███╗ ███╗ ██████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ ███████╗████████╗ █████╗ ██████╗ \n" +
@@ -49,8 +48,8 @@ public final class Emulator {
"██╔████╔██║██║ ██║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗███████╗ ██║ ███████║██████╔╝\n" +
"██║╚██╔╝██║██║ ██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║╚════██║ ██║ ██╔══██║██╔══██╗\n" +
"██║ ╚═╝ ██║╚██████╔╝██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝███████║ ██║ ██║ ██║██║ ██║\n" +
- "╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝\n" +
- " ";
+ "╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝\n" ;
+
public static String build = "";
public static boolean isReady = false;
@@ -83,6 +82,13 @@ public final class Emulator {
Runtime.getRuntime().addShutdownHook(hook);
}
+ public static void promptEnterKey(){
+ System.out.println("\n");
+ System.out.println("Press \"ENTER\" if you agree to the terms stated above...");
+ Scanner scanner = new Scanner(System.in);
+ scanner.nextLine();
+ }
+
public static void main(String[] args) throws Exception {
try {
// Check if running on Windows and not in IntelliJ.
@@ -104,6 +110,12 @@ public final class Emulator {
System.out.println(logo);
+ // Checks if this is a BETA build before allowing them to continue.
+ if (PREVIEW.toLowerCase().contains("beta")) {
+ System.out.println("Warning, this is a beta build, this means that there may be unintended consequences so make sure you take regular backups while using this build. If you notice any issues you should make an issue on the Krews Git.");
+ promptEnterKey();
+ }
+
LOGGER.info("This project is for educational purposes only. This Emulator is an open-source fork of Arcturus created by TheGeneral.");
LOGGER.info("Version: {}", version);
LOGGER.info("Build: {}", build);
@@ -141,7 +153,7 @@ public final class Emulator {
Emulator.rconServer.connect();
Emulator.badgeImager = new BadgeImager();
- LOGGER.info("Arcturus Morningstar has succesfully loaded.");
+ LOGGER.info("Arcturus Morningstar has successfully loaded.");
LOGGER.info("System launched in: {}ms. Using {} threads!", (System.nanoTime() - startTime) / 1e6, Runtime.getRuntime().availableProcessors() * 2);
LOGGER.info("Memory: {}/{}MB", (runtime.totalMemory() - runtime.freeMemory()) / (1024 * 1024), (runtime.freeMemory()) / (1024 * 1024));
@@ -368,6 +380,65 @@ public final class Emulator {
System.exit(0);
}
+ public static int timeStringToSeconds(String timeString) {
+ int totalSeconds = 0;
+
+ Matcher m = Pattern.compile("(([0-9]*) (second|minute|hour|day|week|month|year))").matcher(timeString);
+ Map map = new HashMap() {
+ {
+ put("second", 1);
+ put("minute", 60);
+ put("hour", 3600);
+ put("day", 86400);
+ put("week", 604800);
+ put("month", 2628000);
+ put("year", 31536000);
+ }
+ };
+
+ while (m.find()) {
+ try {
+ int amount = Integer.parseInt(m.group(2));
+ String what = m.group(3);
+ totalSeconds += amount * map.get(what);
+ }
+ catch (Exception ignored) { }
+ }
+
+ return totalSeconds;
+ }
+
+ public static Date modifyDate(Date date, String timeString) {
+ int totalSeconds = 0;
+
+ Calendar c = Calendar.getInstance();
+ c.setTime(date);
+
+ Matcher m = Pattern.compile("(([0-9]*) (second|minute|hour|day|week|month|year))").matcher(timeString);
+ Map map = new HashMap() {
+ {
+ put("second", Calendar.SECOND);
+ put("minute", Calendar.MINUTE);
+ put("hour", Calendar.HOUR);
+ put("day", Calendar.DAY_OF_MONTH);
+ put("week", Calendar.WEEK_OF_MONTH);
+ put("month", Calendar.MONTH);
+ put("year", Calendar.YEAR);
+ }
+ };
+
+ while (m.find()) {
+ try {
+ int amount = Integer.parseInt(m.group(2));
+ String what = m.group(3);
+ c.add(map.get(what), amount);
+ }
+ catch (Exception ignored) { }
+ }
+
+ return c.getTime();
+ }
+
private static String dateToUnixTimestamp(Date date) {
String res = "";
Date aux = stringToDate("1970-01-01 00:00:00");
@@ -378,7 +449,7 @@ public final class Emulator {
return res + seconds;
}
- private static Date stringToDate(String date) {
+ public static Date stringToDate(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date res = null;
try {
diff --git a/src/main/java/com/eu/habbo/core/CleanerThread.java b/src/main/java/com/eu/habbo/core/CleanerThread.java
index b9a721dc..10dcc784 100644
--- a/src/main/java/com/eu/habbo/core/CleanerThread.java
+++ b/src/main/java/com/eu/habbo/core/CleanerThread.java
@@ -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");
}
}
}
diff --git a/src/main/java/com/eu/habbo/core/ConfigurationManager.java b/src/main/java/com/eu/habbo/core/ConfigurationManager.java
index 29e50f73..19b442fe 100644
--- a/src/main/java/com/eu/habbo/core/ConfigurationManager.java
+++ b/src/main/java/com/eu/habbo/core/ConfigurationManager.java
@@ -23,7 +23,7 @@ public class ConfigurationManager {
public boolean loaded = false;
public boolean isLoading = false;
- public ConfigurationManager(String configurationPath) throws Exception {
+ public ConfigurationManager(String configurationPath) {
this.properties = new Properties();
this.configurationPath = configurationPath;
this.reload();
@@ -37,7 +37,12 @@ public class ConfigurationManager {
String envDbHostname = System.getenv("DB_HOSTNAME");
- boolean useEnvVarsForDbConnection = envDbHostname != null && envDbHostname.length() > 1;
+ boolean useEnvVarsForDbConnection = false;
+
+ if(envDbHostname != null)
+ {
+ useEnvVarsForDbConnection = envDbHostname.length() > 1;
+ }
if (!useEnvVarsForDbConnection) {
try {
diff --git a/src/main/java/com/eu/habbo/core/CreditsScheduler.java b/src/main/java/com/eu/habbo/core/CreditsScheduler.java
index d5442bbf..db5e74fb 100644
--- a/src/main/java/com/eu/habbo/core/CreditsScheduler.java
+++ b/src/main/java/com/eu/habbo/core/CreditsScheduler.java
@@ -13,6 +13,7 @@ public class CreditsScheduler extends Scheduler {
public static boolean IGNORE_HOTEL_VIEW;
public static boolean IGNORE_IDLED;
+ public static double HC_MODIFIER;
public CreditsScheduler() {
@@ -24,6 +25,8 @@ public class CreditsScheduler extends Scheduler {
if (Emulator.getConfig().getBoolean("hotel.auto.credits.enabled")) {
IGNORE_HOTEL_VIEW = Emulator.getConfig().getBoolean("hotel.auto.credits.ignore.hotelview");
IGNORE_IDLED = Emulator.getConfig().getBoolean("hotel.auto.credits.ignore.idled");
+ HC_MODIFIER = Emulator.getConfig().getDouble("hotel.auto.credits.hc_modifier", 1.0);
+
if (this.disposed) {
this.disposed = false;
this.run();
@@ -49,7 +52,7 @@ public class CreditsScheduler extends Scheduler {
if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED)
continue;
- habbo.giveCredits(habbo.getHabboInfo().getRank().getCreditsTimerAmount());
+ habbo.giveCredits((int)(habbo.getHabboInfo().getRank().getCreditsTimerAmount() * (habbo.getHabboStats().hasActiveClub() ? HC_MODIFIER : 1.0)));
}
} catch (Exception e) {
LOGGER.error("Caught exception", e);
diff --git a/src/main/java/com/eu/habbo/core/Easter.java b/src/main/java/com/eu/habbo/core/Easter.java
index ea643841..f358dbc8 100644
--- a/src/main/java/com/eu/habbo/core/Easter.java
+++ b/src/main/java/com/eu/habbo/core/Easter.java
@@ -1,5 +1,6 @@
package com.eu.habbo.core;
+import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
@@ -11,7 +12,7 @@ import com.eu.habbo.plugin.events.users.UserSavedMottoEvent;
public class Easter {
@EventHandler
public static void onUserChangeMotto(UserSavedMottoEvent event) {
- if (event.newMotto.equalsIgnoreCase("crickey!")) {
+ if (Emulator.getConfig().getBoolean("easter_eggs.enabled") && event.newMotto.equalsIgnoreCase("crickey!")) {
event.habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(event.newMotto, event.habbo, event.habbo, RoomChatMessageBubbles.ALERT)));
Room room = event.habbo.getHabboInfo().getCurrentRoom();
diff --git a/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java b/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java
index 58b3acc7..58350a95 100644
--- a/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java
+++ b/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java
@@ -14,6 +14,7 @@ public class GotwPointsScheduler extends Scheduler {
public static boolean IGNORE_HOTEL_VIEW;
public static boolean IGNORE_IDLED;
public static String GOTW_POINTS_NAME;
+ public static double HC_MODIFIER;
public GotwPointsScheduler() { //TODO MOVE TO A PLUGIN. IS NOT PART OF OFFICIAL HABBO.
@@ -25,6 +26,7 @@ public class GotwPointsScheduler extends Scheduler {
if (Emulator.getConfig().getBoolean("hotel.auto.gotwpoints.enabled")) {
IGNORE_HOTEL_VIEW = Emulator.getConfig().getBoolean("hotel.auto.gotwpoints.ignore.hotelview");
IGNORE_IDLED = Emulator.getConfig().getBoolean("hotel.auto.gotwpoints.ignore.idled");
+ HC_MODIFIER = Emulator.getConfig().getDouble("hotel.auto.gotwpoints.hc_modifier", 1.0);
GOTW_POINTS_NAME = Emulator.getConfig().getValue("hotel.auto.gotwpoints.name");
if (this.disposed) {
@@ -62,8 +64,7 @@ public class GotwPointsScheduler extends Scheduler {
}
type = Emulator.getConfig().getInt("seasonal.currency." + GOTW_POINTS_NAME, -1);
if (found || type != -1) {
-
- habbo.givePoints(type, habbo.getHabboInfo().getRank().getGotwTimerAmount());
+ habbo.givePoints(type, (int)(habbo.getHabboInfo().getRank().getGotwTimerAmount() * (habbo.getHabboStats().hasActiveClub() ? HC_MODIFIER : 1.0)));
}
}
} catch (Exception e) {
diff --git a/src/main/java/com/eu/habbo/core/PixelScheduler.java b/src/main/java/com/eu/habbo/core/PixelScheduler.java
index cadf07ea..2b0bddd5 100644
--- a/src/main/java/com/eu/habbo/core/PixelScheduler.java
+++ b/src/main/java/com/eu/habbo/core/PixelScheduler.java
@@ -13,6 +13,7 @@ public class PixelScheduler extends Scheduler {
public static boolean IGNORE_HOTEL_VIEW;
public static boolean IGNORE_IDLED;
+ public static double HC_MODIFIER;
public PixelScheduler() {
super(Emulator.getConfig().getInt("hotel.auto.pixels.interval"));
@@ -23,6 +24,7 @@ public class PixelScheduler extends Scheduler {
if (Emulator.getConfig().getBoolean("hotel.auto.pixels.enabled")) {
IGNORE_HOTEL_VIEW = Emulator.getConfig().getBoolean("hotel.auto.pixels.ignore.hotelview");
IGNORE_IDLED = Emulator.getConfig().getBoolean("hotel.auto.pixels.ignore.idled");
+ HC_MODIFIER = Emulator.getConfig().getDouble("hotel.auto.pixels.hc_modifier", 1.0);
if (this.disposed) {
this.disposed = false;
this.run();
@@ -47,7 +49,7 @@ public class PixelScheduler extends Scheduler {
if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED)
continue;
- habbo.givePixels(habbo.getHabboInfo().getRank().getPixelsTimerAmount());
+ habbo.givePixels((int)(habbo.getHabboInfo().getRank().getPixelsTimerAmount() * (habbo.getHabboStats().hasActiveClub() ? HC_MODIFIER : 1.0)));
}
} catch (Exception e) {
LOGGER.error("Caught exception", e);
diff --git a/src/main/java/com/eu/habbo/core/PointsScheduler.java b/src/main/java/com/eu/habbo/core/PointsScheduler.java
index d30abc6a..ca863cb8 100644
--- a/src/main/java/com/eu/habbo/core/PointsScheduler.java
+++ b/src/main/java/com/eu/habbo/core/PointsScheduler.java
@@ -13,6 +13,7 @@ public class PointsScheduler extends Scheduler {
public static boolean IGNORE_HOTEL_VIEW;
public static boolean IGNORE_IDLED;
+ public static double HC_MODIFIER;
public PointsScheduler() {
@@ -24,6 +25,7 @@ public class PointsScheduler extends Scheduler {
if (Emulator.getConfig().getBoolean("hotel.auto.points.enabled")) {
IGNORE_HOTEL_VIEW = Emulator.getConfig().getBoolean("hotel.auto.points.ignore.hotelview");
IGNORE_IDLED = Emulator.getConfig().getBoolean("hotel.auto.points.ignore.idled");
+ HC_MODIFIER = Emulator.getConfig().getDouble("hotel.auto.points.hc_modifier", 1.0);
if (this.disposed) {
this.disposed = false;
this.run();
@@ -50,7 +52,7 @@ public class PointsScheduler extends Scheduler {
continue;
//habbo.givePoints(POINTS);
- habbo.givePoints(habbo.getHabboInfo().getRank().getDiamondsTimerAmount());
+ habbo.givePoints((int)(habbo.getHabboInfo().getRank().getDiamondsTimerAmount() * (habbo.getHabboStats().hasActiveClub() ? HC_MODIFIER : 1.0)));
}
} catch (Exception e) {
LOGGER.error("Caught exception", e);
diff --git a/src/main/java/com/eu/habbo/core/TextsManager.java b/src/main/java/com/eu/habbo/core/TextsManager.java
index 90c6520a..4b0bf66e 100644
--- a/src/main/java/com/eu/habbo/core/TextsManager.java
+++ b/src/main/java/com/eu/habbo/core/TextsManager.java
@@ -72,7 +72,7 @@ public class TextsManager {
public int getInt(String key, Integer defaultValue) {
try {
return Integer.parseInt(this.getValue(key, defaultValue.toString()));
- } catch (Exception e) {
+ } catch (NumberFormatException e) {
LOGGER.error("Caught exception", e);
}
return defaultValue;
diff --git a/src/main/java/com/eu/habbo/database/Database.java b/src/main/java/com/eu/habbo/database/Database.java
index c37a524a..00be0fee 100644
--- a/src/main/java/com/eu/habbo/database/Database.java
+++ b/src/main/java/com/eu/habbo/database/Database.java
@@ -3,9 +3,18 @@ package com.eu.habbo.database;
import com.eu.habbo.Emulator;
import com.eu.habbo.core.ConfigurationManager;
import com.zaxxer.hikari.HikariDataSource;
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
public class Database {
private static final Logger LOGGER = LoggerFactory.getLogger(Database.class);
@@ -53,4 +62,52 @@ public class Database {
public DatabasePool getDatabasePool() {
return this.databasePool;
}
+
+ public static PreparedStatement preparedStatementWithParams(Connection connection, String query, THashMap queryParams) throws SQLException {
+ THashMap params = new THashMap();
+ THashSet quotedParams = new THashSet<>();
+
+ for(String key : queryParams.keySet()) {
+ quotedParams.add(Pattern.quote(key));
+ }
+
+ String regex = "(" + String.join("|", quotedParams) + ")";
+
+ Matcher m = Pattern.compile(regex).matcher(query);
+
+ int i = 1;
+
+ while (m.find()) {
+ try {
+ params.put(i, queryParams.get(m.group(1)));
+ i++;
+ }
+ catch (Exception ignored) { }
+ }
+
+ PreparedStatement statement = connection.prepareStatement(query.replaceAll(regex, "?"));
+
+ for(Map.Entry set : params.entrySet()) {
+ if(set.getValue().getClass() == String.class) {
+ statement.setString(set.getKey(), (String)set.getValue());
+ }
+ else if(set.getValue().getClass() == Integer.class) {
+ statement.setInt(set.getKey(), (Integer)set.getValue());
+ }
+ else if(set.getValue().getClass() == Double.class) {
+ statement.setDouble(set.getKey(), (Double)set.getValue());
+ }
+ else if(set.getValue().getClass() == Float.class) {
+ statement.setFloat(set.getKey(), (Float)set.getValue());
+ }
+ else if(set.getValue().getClass() == Long.class) {
+ statement.setLong(set.getKey(), (Long)set.getValue());
+ }
+ else {
+ statement.setObject(set.getKey(), set.getValue());
+ }
+ }
+
+ return statement;
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
index 63a956bb..a614cb05 100644
--- a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
+++ b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java
@@ -20,6 +20,8 @@ import com.eu.habbo.habbohotel.pets.PetManager;
import com.eu.habbo.habbohotel.polls.PollManager;
import com.eu.habbo.habbohotel.rooms.RoomManager;
import com.eu.habbo.habbohotel.users.HabboManager;
+import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionManager;
+import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionScheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,6 +33,8 @@ public class GameEnvironment {
public PixelScheduler pixelScheduler;
public PointsScheduler pointsScheduler;
public GotwPointsScheduler gotwPointsScheduler;
+ public SubscriptionScheduler subscriptionScheduler;
+
private HabboManager habboManager;
private NavigatorManager navigatorManager;
private GuildManager guildManager;
@@ -49,6 +53,7 @@ public class GameEnvironment {
private WordFilter wordFilter;
private CraftingManager craftingManager;
private PollManager pollManager;
+ private SubscriptionManager subscriptionManager;
public void load() throws Exception {
LOGGER.info("GameEnvironment -> Loading...");
@@ -86,6 +91,11 @@ public class GameEnvironment {
this.gotwPointsScheduler = new GotwPointsScheduler();
Emulator.getThreading().run(this.gotwPointsScheduler);
+ this.subscriptionManager = new SubscriptionManager();
+ this.subscriptionManager.init();
+
+ this.subscriptionScheduler = new SubscriptionScheduler();
+ Emulator.getThreading().run(this.subscriptionScheduler);
LOGGER.info("GameEnvironment -> Loaded!");
}
@@ -103,6 +113,7 @@ public class GameEnvironment {
this.roomManager.dispose();
this.itemManager.dispose();
this.hotelViewManager.dispose();
+ this.subscriptionManager.dispose();
LOGGER.info("GameEnvironment -> Disposed!");
}
@@ -191,4 +202,8 @@ public class GameEnvironment {
public GotwPointsScheduler getGotwPointsScheduler() { return this.gotwPointsScheduler;
}
+
+ public SubscriptionManager getSubscriptionManager() {
+ return this.subscriptionManager;
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
index 8cedc5ff..b1149aa9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
+++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java
@@ -44,6 +44,7 @@ public class Bot implements Runnable {
private int chatTimeOut;
private int chatTimestamp;
private short lastChatIndex;
+ private int bubble;
private String type;
@@ -73,6 +74,7 @@ public class Bot implements Runnable {
this.chatLines = new ArrayList<>();
this.type = "generic_bot";
this.room = null;
+ this.bubble = RoomChatMessageBubbles.BOT_RENTABLE.getType();
}
public Bot(ResultSet set) throws SQLException {
@@ -94,6 +96,7 @@ public class Bot implements Runnable {
this.roomUnit = null;
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
this.needsUpdate = false;
+ this.bubble = set.getInt("bubble_id");
}
public Bot(Bot bot) {
@@ -110,6 +113,7 @@ public class Bot implements Runnable {
this.chatLines = new ArrayList<>(Arrays.asList("Default Message :D"));
this.type = bot.getType();
this.effect = bot.getEffect();
+ this.bubble = bot.getBubbleId();
this.needsUpdate = false;
}
@@ -133,7 +137,7 @@ public class Bot implements Runnable {
@Override
public void run() {
if (this.needsUpdate) {
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ? WHERE id = ?")) {
+ try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
statement.setString(1, this.name);
statement.setString(2, this.motto);
statement.setString(3, this.figure);
@@ -155,7 +159,8 @@ public class Bot implements Runnable {
statement.setString(15, this.chatRandom ? "1" : "0");
statement.setInt(16, this.chatDelay);
statement.setInt(17, this.effect);
- statement.setInt(18, this.id);
+ statement.setInt(18, this.bubble);
+ statement.setInt(19, this.id);
statement.execute();
this.needsUpdate = false;
} catch (SQLException e) {
@@ -173,11 +178,11 @@ public class Bot implements Runnable {
int timeOut = Emulator.getRandom().nextInt(20) * 2;
this.roomUnit.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp());
}
- } else {
+ }/* else {
for (RoomTile t : this.room.getLayout().getTilesAround(this.room.getLayout().getTile(this.getRoomUnit().getX(), this.getRoomUnit().getY()))) {
WiredHandler.handle(WiredTriggerType.BOT_REACHED_STF, this.roomUnit, this.room, this.room.getItemsAt(t).toArray());
}
- }
+ }*/
}
if (!this.chatLines.isEmpty() && this.chatTimeOut <= Emulator.getIntUnixTimestamp() && this.chatAuto) {
@@ -188,12 +193,16 @@ public class Bot implements Runnable {
this.lastChatIndex = 0;
}
- this.talk(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() + ""));
+ String message = this.chatLines.get(this.lastChatIndex)
+ .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);
+ }
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
}
@@ -208,7 +217,7 @@ public class Bot implements Runnable {
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
- this.room.botChat(new RoomUserTalkComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.BOT_RENTABLE)).compose());
+ this.room.botChat(new RoomUserTalkComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
if (message.equals("o/") || message.equals("_o/")) {
this.room.sendComposer(new RoomUserActionComposer(this.roomUnit, RoomUserAction.WAVE).compose());
@@ -223,7 +232,7 @@ public class Bot implements Runnable {
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
- this.room.botChat(new RoomUserShoutComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.BOT_RENTABLE)).compose());
+ this.room.botChat(new RoomUserShoutComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
if (message.equals("o/") || message.equals("_o/")) {
this.room.sendComposer(new RoomUserActionComposer(this.roomUnit, RoomUserAction.WAVE).compose());
@@ -238,7 +247,7 @@ public class Bot implements Runnable {
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
- event.target.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.BOT_RENTABLE)));
+ event.target.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(event.message, this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))));
}
}
@@ -247,7 +256,12 @@ public class Bot implements Runnable {
room.giveEffect(this.roomUnit, this.effect, -1);
}
- this.talk(PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)]);
+ if(PLACEMENT_MESSAGES.length > 0) {
+ String message = PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)];
+ if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{message})) {
+ this.talk(message);
+ }
+ }
}
public void onPickUp(Habbo habbo, Room room) {
@@ -270,6 +284,10 @@ public class Bot implements Runnable {
return this.name;
}
+ public int getBubbleId() {
+ return bubble;
+ }
+
public void setName(String name) {
this.name = name;
this.needsUpdate = true;
diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java
index 1f93888c..9a8129ae 100644
--- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java
+++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java
@@ -12,6 +12,7 @@ import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.inventory.AddBotComposer;
import com.eu.habbo.messages.outgoing.inventory.RemoveBotComposer;
+import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
@@ -48,13 +49,8 @@ public class BotManager {
}
public static void addBotDefinition(String type, Class extends Bot> botClazz) throws Exception {
- if (botClazz.getDeclaredConstructor(ResultSet.class) == null) {
- throw new Exception("Missing Bot(ResultSet) constructor!");
- } else {
- botClazz.getDeclaredConstructor(ResultSet.class).setAccessible(true);
-
- botDefenitions.put(type, botClazz);
- }
+ botClazz.getDeclaredConstructor(ResultSet.class).setAccessible(true);
+ botDefenitions.put(type, botClazz);
}
public boolean reload() {
@@ -144,6 +140,7 @@ public class BotManager {
room.addBot(bot);
Emulator.getThreading().run(bot);
room.sendComposer(new RoomUsersComposer(bot).compose());
+ room.sendComposer(new RoomUserStatusComposer(bot.getRoomUnit()).compose());
habbo.getInventory().getBotsComponent().removeBot(bot);
habbo.getClient().sendResponse(new RemoveBotComposer(bot));
bot.onPlace(habbo, room);
diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
index d776bee9..b5acb9f2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
+++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java
@@ -3,6 +3,8 @@ package com.eu.habbo.habbohotel.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
+import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.plugin.events.bots.BotServerItemEvent;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit;
@@ -56,54 +58,86 @@ 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, 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 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 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(() -> b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername())));
+ tasks.add(() -> {
+ if(this.getRoom() != null) {
+ String botMessage = Emulator.getTexts()
+ .getValue("bots.butler.given")
+ .replace("%key%", key)
+ .replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
- List 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 (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{ botMessage })) {
+ bot.talk(botMessage);
}
}
});
+ List failedReached = new ArrayList<>();
+ failedReached.add(() -> {
+ 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);
- this.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()));
+ if(this.getRoom() != null) {
+ 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);
+ }
+ }
}
return;
}
}
}
}
+ }
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
index 255031af..6e7908c2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
+++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java
@@ -615,6 +615,16 @@ public class CatalogManager {
.findAny().orElse(null);
}
+ public CatalogPage getCatalogPageByLayout(String layoutName) {
+ return this.catalogPages.valueCollection().stream()
+ .filter(p -> p != null &&
+ p.isVisible() &&
+ p.isEnabled() &&
+ p.getRank() < 2 &&
+ p.getLayout() != null && p.getLayout().equalsIgnoreCase(layoutName)
+ )
+ .findAny().orElse(null);
+ }
public CatalogItem getCatalogItem(int id) {
final CatalogItem[] item = {null};
@@ -639,10 +649,19 @@ public class CatalogManager {
this.catalogPages.get(parentId).childPages.forEachValue(new TObjectProcedure() {
@Override
public boolean execute(CatalogPage object) {
- if (object.getRank() <= habbo.getHabboInfo().getRank().getId() && object.visible) {
- pages.add(object);
+
+ boolean isVisiblePage = object.visible;
+ boolean hasRightRank = object.getRank() <= habbo.getHabboInfo().getRank().getId();
+
+ boolean clubRightsOkay = true;
+
+ if(object.isClubOnly() && !habbo.getHabboInfo().getHabboStats().hasActiveClub()) {
+ clubRightsOkay = false;
}
+ if (isVisiblePage && hasRightRank && clubRightsOkay) {
+ pages.add(object);
+ }
return true;
}
});
@@ -1060,9 +1079,6 @@ public class CatalogManager {
}
}
- UserCatalogItemPurchasedEvent purchasedEvent = new UserCatalogItemPurchasedEvent(habbo, item, itemsList, totalCredits, totalPoints, badges);
- Emulator.getPluginManager().fireEvent(purchasedEvent);
-
if (badgeFound) {
habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.ALREADY_HAVE_BADGE));
@@ -1071,6 +1087,9 @@ public class CatalogManager {
}
}
+ UserCatalogItemPurchasedEvent purchasedEvent = new UserCatalogItemPurchasedEvent(habbo, item, itemsList, totalCredits, totalPoints, badges);
+ Emulator.getPluginManager().fireEvent(purchasedEvent);
+
if (!free && !habbo.getClient().getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) {
if (purchasedEvent.totalCredits > 0) {
habbo.getClient().getHabbo().getHabboInfo().addCredits(-purchasedEvent.totalCredits);
@@ -1121,6 +1140,26 @@ public class CatalogManager {
habbo.getClient().sendResponse(new PurchaseOKComposer(purchasedEvent.catalogItem));
habbo.getClient().sendResponse(new InventoryRefreshComposer());
+ THashSet itemIds = new THashSet<>();
+
+ for(HabboItem ix : purchasedEvent.itemsList) {
+ itemIds.add(ix.getId() + "");
+ }
+
+ if(!free) {
+ Emulator.getThreading().run(new CatalogPurchaseLogEntry(
+ Emulator.getIntUnixTimestamp(),
+ purchasedEvent.habbo.getHabboInfo().getId(),
+ purchasedEvent.catalogItem != null ? purchasedEvent.catalogItem.getId() : 0,
+ String.join(";", itemIds),
+ purchasedEvent.catalogItem != null ? purchasedEvent.catalogItem.getName() : "",
+ purchasedEvent.totalCredits,
+ purchasedEvent.totalPoints,
+ item != null ? item.getPointsType() : 0,
+ amount
+ ));
+ }
+
} catch (Exception e) {
LOGGER.error("Exception caught", e);
habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR));
diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPurchaseLogEntry.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPurchaseLogEntry.java
new file mode 100644
index 00000000..5f6febd7
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogPurchaseLogEntry.java
@@ -0,0 +1,61 @@
+package com.eu.habbo.habbohotel.catalog;
+
+import com.eu.habbo.Emulator;
+import com.eu.habbo.core.DatabaseLoggable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+public class CatalogPurchaseLogEntry implements Runnable, DatabaseLoggable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CatalogPurchaseLogEntry.class);
+ private static final String QUERY = "INSERT INTO `logs_shop_purchases` (timestamp, user_id, catalog_item_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ private final int timestamp;
+ private final int userId;
+ private final int catalogItemId;
+ private final String itemIds;
+ private final String catalogName;
+ private final int costCredits;
+ private final int costPoints;
+ private final int pointsType;
+ private final int amount;
+
+ public CatalogPurchaseLogEntry(int timestamp, int userId, int catalogItemId, String itemIds, String catalogName, int costCredits, int costPoints, int pointsType, int amount) {
+ this.timestamp = timestamp;
+ this.userId = userId;
+ this.catalogItemId = catalogItemId;
+ this.itemIds = itemIds;
+ this.catalogName = catalogName;
+ this.costCredits = costCredits;
+ this.costPoints = costPoints;
+ this.pointsType = pointsType;
+ this.amount = amount;
+ }
+
+ @Override
+ public String getQuery() {
+ return QUERY;
+ }
+
+ @Override
+ public void log(PreparedStatement statement) throws SQLException {
+ statement.setInt(1, this.timestamp);
+ statement.setInt(2, this.userId);
+ statement.setInt(3, this.catalogItemId);
+ statement.setString(4, this.itemIds);
+ statement.setString(5, this.catalogName);
+ statement.setInt(6, this.costCredits);
+ statement.setInt(7, this.costPoints);
+ statement.setInt(8, this.pointsType);
+ statement.setInt(9, this.amount);
+ statement.addBatch();
+ }
+
+ @Override
+ public void run() {
+ Emulator.getDatabaseLogger().store(this);
+ }
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/ClubOffer.java b/src/main/java/com/eu/habbo/habbohotel/catalog/ClubOffer.java
index 4ba103ba..3be967be 100644
--- a/src/main/java/com/eu/habbo/habbohotel/catalog/ClubOffer.java
+++ b/src/main/java/com/eu/habbo/habbohotel/catalog/ClubOffer.java
@@ -1,9 +1,15 @@
package com.eu.habbo.habbohotel.catalog;
+import com.eu.habbo.Emulator;
+import com.eu.habbo.messages.ISerialize;
+import com.eu.habbo.messages.ServerMessage;
+
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.TimeZone;
-public class ClubOffer {
+public class ClubOffer implements ISerialize {
private final int id;
@@ -70,4 +76,47 @@ public class ClubOffer {
public boolean isDeal() {
return this.deal;
}
+
+ @Override
+ public void serialize(ServerMessage message) {
+ serialize(message, Emulator.getIntUnixTimestamp());
+ }
+
+ public void serialize(ServerMessage message, int hcExpireTimestamp) {
+ hcExpireTimestamp = Math.max(Emulator.getIntUnixTimestamp(), hcExpireTimestamp);
+ message.appendInt(this.id);
+ message.appendString(this.name);
+ message.appendBoolean(false); //unused
+ message.appendInt(this.credits);
+ message.appendInt(this.points);
+ message.appendInt(this.pointsType);
+ message.appendBoolean(this.vip);
+
+ long seconds = this.days * 86400;
+
+ long secondsTotal = seconds;
+
+ int totalYears = (int) Math.floor((int) seconds / (86400.0 * 31 * 12));
+ seconds -= totalYears * (86400 * 31 * 12);
+
+ int totalMonths = (int) Math.floor((int) seconds / (86400.0 * 31));
+ seconds -= totalMonths * (86400 * 31);
+
+ int totalDays = (int) Math.floor((int) seconds / 86400.0);
+ seconds -= totalDays * 86400;
+
+ message.appendInt((int) secondsTotal / 86400 / 31);
+ message.appendInt((int) seconds);
+ message.appendBoolean(false); //giftable
+ message.appendInt((int) seconds);
+
+ hcExpireTimestamp += secondsTotal;
+
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeZone(TimeZone.getTimeZone("UTC"));
+ cal.setTimeInMillis(hcExpireTimestamp * 1000L);
+ message.appendInt(cal.get(Calendar.YEAR));
+ message.appendInt(cal.get(Calendar.MONTH) + 1);
+ message.appendInt(cal.get(Calendar.DAY_OF_MONTH));
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java b/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java
index 680d3e9b..d283ada6 100644
--- a/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java
+++ b/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java
@@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.catalog.CatalogItem;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomManager;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
@@ -133,7 +134,7 @@ public class RoomBundleLayout extends SingleBundle {
if (habbo != null) {
int count = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(habbo).size();
- int max = habbo.getHabboStats().hasActiveClub() ? Emulator.getConfig().getInt("hotel.max.rooms.vip") : Emulator.getConfig().getInt("hotel.max.rooms.user");
+ int max = habbo.getHabboStats().hasActiveClub() ? RoomManager.MAXIMUM_ROOMS_HC : RoomManager.MAXIMUM_ROOMS_USER;
if (count >= max) {
habbo.getClient().sendResponse(new CanCreateRoomComposer(count, max));
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
index ab4ece28..b3a111a9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java
@@ -3,7 +3,10 @@ package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogManager;
import com.eu.habbo.habbohotel.gameclients.GameClient;
+import com.eu.habbo.habbohotel.users.HabboManager;
+import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer;
+import java.util.Collections;
import java.util.concurrent.TimeUnit;
@@ -11,9 +14,12 @@ public class AboutCommand extends Command {
public AboutCommand() {
super(null, new String[]{"about", "info", "online", "server"});
}
-
+ 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 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\n Snaiker\n Thijmen";
@Override
public boolean handle(GameClient gameClient, String[] params) {
+
Emulator.getRuntime().gc();
int seconds = Emulator.getIntUnixTimestamp() - Emulator.getTimeStarted();
@@ -42,9 +48,8 @@ public class AboutCommand extends Command {
"Thanks for using Arcturus. Report issues on the forums. http://arcturus.wf \r\r" +
" - The General";
-
gameClient.getHabbo().alert(message);
-
+ gameClient.sendResponse(new MessagesForYouComposer(Collections.singletonList(credits)));
return true;
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java b/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
index 16d2c5c9..a37d9482 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java
@@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.pets.PetCommand;
import com.eu.habbo.habbohotel.pets.PetVocalsType;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTypingComposer;
import com.eu.habbo.plugin.events.users.UserCommandEvent;
import com.eu.habbo.plugin.events.users.UserExecuteCommandEvent;
@@ -72,9 +73,14 @@ public class CommandHandler {
for (String s : command.keys) {
if (s.toLowerCase().equals(parts[0].toLowerCase())) {
boolean succes = false;
- if (command.permission == null || gameClient.getHabbo().hasPermission(command.permission, gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && (gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) || (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildId() > 0 && gameClient.getHabbo().getHabboInfo().getCurrentRoom().guildRightLevel(gameClient.getHabbo()) >= 2))) {
+ if (command.permission == null || gameClient.getHabbo().hasPermission(command.permission, gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && (gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermission(Permission.ACC_PLACEFURNI) || (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildId() > 0 && gameClient.getHabbo().getHabboInfo().getCurrentRoom().getGuildRightLevel(gameClient.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS)))) {
try {
- Emulator.getPluginManager().fireEvent(new UserExecuteCommandEvent(gameClient.getHabbo(), command, parts));
+ UserExecuteCommandEvent userExecuteCommandEvent = new UserExecuteCommandEvent(gameClient.getHabbo(), command, parts);
+ Emulator.getPluginManager().fireEvent(userExecuteCommandEvent);
+
+ if(userExecuteCommandEvent.isCancelled()) {
+ return userExecuteCommandEvent.isSuccess();
+ }
if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null)
gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserTypingComposer(gameClient.getHabbo().getRoomUnit(), false).compose());
@@ -211,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());
@@ -285,6 +292,7 @@ public class CommandHandler {
addCommand(new UpdateYoutubePlaylistsCommand());
addCommand(new AddYoutubePlaylistCommand());
addCommand(new SoftKickCommand());
+ addCommand(new SubscriptionCommand());
addCommand(new TestCommand());
}
@@ -313,4 +321,4 @@ public class CommandHandler {
commands.clear();
LOGGER.info("Command Handler -> Disposed!");
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/EjectAllCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/EjectAllCommand.java
index 8e5ab590..51fa9589 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/EjectAllCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/EjectAllCommand.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomRightLevels;
public class EjectAllCommand extends Command {
public EjectAllCommand() {
@@ -14,7 +15,7 @@ public class EjectAllCommand extends Command {
Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom();
if (room != null) {
- if (room.isOwner(gameClient.getHabbo()) || (room.hasGuild() && room.guildRightLevel(gameClient.getHabbo()) == 3)) {
+ if (room.isOwner(gameClient.getHabbo()) || (room.hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) {
room.ejectAll(gameClient.getHabbo());
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java
index 123f1db4..13d72c30 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java
@@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
+import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManager;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer;
import com.eu.habbo.messages.outgoing.users.UserDataComposer;
import com.eu.habbo.util.figure.FigureUtil;
@@ -35,7 +36,7 @@ public class MimicCommand extends Command {
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_mimic.forbidden_clothing"), RoomChatMessageBubbles.ALERT);
return true;
} else {
- gameClient.getHabbo().getHabboInfo().setLook(habbo.getHabboInfo().getLook());
+ gameClient.getHabbo().getHabboInfo().setLook(ClothingValidationManager.VALIDATE_ON_MIMIC ? ClothingValidationManager.validateLook(gameClient.getHabbo(), habbo.getHabboInfo().getLook(), habbo.getHabboInfo().getGender().name()) : habbo.getHabboInfo().getLook());
gameClient.getHabbo().getHabboInfo().setGender(habbo.getHabboInfo().getGender());
gameClient.sendResponse(new UserDataComposer(gameClient.getHabbo()));
gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserDataComposer(gameClient.getHabbo()).compose());
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java
new file mode 100644
index 00000000..a2693217
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java
@@ -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 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;
+ }
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/SubscriptionCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/SubscriptionCommand.java
new file mode 100644
index 00000000..25f8b758
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/SubscriptionCommand.java
@@ -0,0 +1,109 @@
+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.HabboInfo;
+import com.eu.habbo.habbohotel.users.HabboManager;
+import com.eu.habbo.habbohotel.users.subscriptions.Subscription;
+
+/**
+ * @author Beny
+ */
+public class SubscriptionCommand extends Command {
+ public SubscriptionCommand() {
+ super("cmd_subscription", Emulator.getTexts().getValue("commands.keys.cmd_subscription").split(";"));
+ }
+
+ /**
+ * Allows you to give/extend/remove subscription on a given user.
+ *
+ * Parameters:
+ * [username] = Username of user to execute command on
+ * [type] = Subscription type (e.g. HABBO_CLUB)
+ * [add|remove] = Use add or remove to increase/decrease sub duration
+ * [time] = Time string e.g. "1 week", "18 days", "4 minutes". Can be complex e.g. "1 month 5 days 2 minutes"
+ *
+ * Examples:
+ * :sub Beny habbo_club add 1 month - adds 1 month of HABBO_CLUB subscription duration on the user Beny
+ * :sub Beny builders_club add 1 month - adds 1 month of BUILDERS_CLUB subscription duration on the user Beny
+ * :sub Beny habbo_club remove 3 days - removes 3 days of HABBO_CLUB subscription duration on the user Beny
+ * :sub Beny habbo_club remove - removes all remaining time from the HABBO_CLUB subscription (expires it) on the user Beny
+ *
+ * @param gameClient Client that executed the command
+ * @param params Command parameters
+ * @return Boolean indicating success
+ * @throws Exception Exception
+ */
+ @Override
+ public boolean handle(GameClient gameClient, String[] params) throws Exception {
+ if (params.length >= 4) {
+ HabboInfo info = HabboManager.getOfflineHabboInfo(params[1]);
+
+ if (info != null) {
+ Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(params[1]);
+
+ String subscription = params[2].toUpperCase();
+ String action = params[3];
+
+ StringBuilder message = new StringBuilder();
+ if (params.length > 4) {
+ for (int i = 4; i < params.length; i++) {
+ message.append(params[i]).append(" ");
+ }
+ }
+
+ if(!Emulator.getGameEnvironment().getSubscriptionManager().types.containsKey(subscription)) {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.type_not_found", "%subscription% is not a valid subscription type").replace("%subscription%", subscription), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
+
+ if(action.equalsIgnoreCase("add") || action.equalsIgnoreCase("+") || action.equalsIgnoreCase("a")) {
+ int timeToAdd = Emulator.timeStringToSeconds(message.toString());
+
+ if(timeToAdd < 1) {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.invalid_params_time", "Invalid time span, try: x minutes/days/weeks/months"), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
+
+ habbo.getHabboStats().createSubscription(subscription, timeToAdd);
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.success_add_time", "Successfully added %time% seconds to %subscription% on %user%").replace("%time%", timeToAdd + "").replace("%user%", params[1]).replace("%subscription%", subscription), RoomChatMessageBubbles.ALERT);
+ }
+ else if(action.equalsIgnoreCase("remove") || action.equalsIgnoreCase("-") || action.equalsIgnoreCase("r")) {
+ Subscription s = habbo.getHabboStats().getSubscription(subscription);
+
+ if (s == null) {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.user_not_have", "%user% does not have the %subscription% subscription").replace("%user%", params[1]).replace("%subscription%", subscription), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
+
+ if(message.length() != 0) {
+ int timeToRemove = Emulator.timeStringToSeconds(message.toString());
+
+ if (timeToRemove < 1) {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.invalid_params_time", "Invalid time span, try: x minutes/days/weeks/months"), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
+
+ s.addDuration(-timeToRemove);
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.success_remove_time", "Successfully removed %time% seconds from %subscription% on %user%").replace("%time%", timeToRemove + "").replace("%user%", params[1]).replace("%subscription%", subscription), RoomChatMessageBubbles.ALERT);
+ }
+ else {
+ s.addDuration(-s.getRemaining());
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.success_remove_sub", "Successfully removed %subscription% sub from %user%").replace("%user%", params[1]).replace("%subscription%", subscription), RoomChatMessageBubbles.ALERT);
+ }
+ }
+ else {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.invalid_action", "Invalid action specified. Must be add, +, remove or -"), RoomChatMessageBubbles.ALERT);
+ }
+
+ } else {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.user_not_found", "%user% was not found").replace("%user%", params[1]), RoomChatMessageBubbles.ALERT);
+ }
+ } else {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_subscription.invalid_params", "Invalid command format"), RoomChatMessageBubbles.ALERT);
+ }
+ return true;
+ }
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/UpdateNavigatorCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/UpdateNavigatorCommand.java
index c01c2e94..ee3b5f9a 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/UpdateNavigatorCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/UpdateNavigatorCommand.java
@@ -13,7 +13,7 @@ public class UpdateNavigatorCommand extends Command {
public boolean handle(GameClient gameClient, String[] params) throws Exception {
Emulator.getGameEnvironment().getNavigatorManager().loadNavigator();
Emulator.getGameEnvironment().getRoomManager().loadRoomModels();
- Emulator.getGameEnvironment().getRoomManager().loadPublicRooms();
+
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_update_navigator"), RoomChatMessageBubbles.ALERT);
return true;
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
index fdd621c8..b4a3ca78 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java
@@ -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());
diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/WordQuizCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/WordQuizCommand.java
index 09a6c4dc..ba74d5d2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/commands/WordQuizCommand.java
+++ b/src/main/java/com/eu/habbo/habbohotel/commands/WordQuizCommand.java
@@ -2,6 +2,9 @@ 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 java.util.Arrays;
public class WordQuizCommand extends Command {
public WordQuizCommand() {
@@ -11,21 +14,21 @@ public class WordQuizCommand extends Command {
@Override
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (!gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasActiveWordQuiz()) {
+ if(params.length == 1) {
+ gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.description.cmd_word_quiz"), RoomChatMessageBubbles.ALERT);
+ return true;
+ }
StringBuilder question = new StringBuilder();
int duration = 60;
- if (params.length > 2) {
- for (int i = 1; i < params.length - 1; i++) {
- question.append(" ").append(params[i]);
- }
+ try {
+ duration = Integer.parseInt(params[params.length-1]);
+ params = Arrays.copyOf(params, params.length-1);
+ }
+ catch (Exception e) {}
- try {
- duration = Integer.valueOf(params[params.length - 1]);
- } catch (Exception e) {
- question.append(" ").append(params[params.length - 1]);
- }
- } else {
- question = new StringBuilder(params[1]);
+ for (int i = 1; i < params.length; i++) {
+ question.append(" ").append(params[i]);
}
gameClient.getHabbo().getHabboInfo().getCurrentRoom().startWordQuiz(question.toString(), duration * 1000);
diff --git a/src/main/java/com/eu/habbo/habbohotel/games/Game.java b/src/main/java/com/eu/habbo/habbohotel/games/Game.java
index 16783eb7..24a8051d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/games/Game.java
+++ b/src/main/java/com/eu/habbo/habbohotel/games/Game.java
@@ -95,7 +95,9 @@ public abstract class Game implements Runnable {
if (team != null && team.isMember(habbo)) {
if (habbo.getHabboInfo().getGamePlayer() != null) {
team.removeMember(habbo.getHabboInfo().getGamePlayer());
- habbo.getHabboInfo().getGamePlayer().reset();
+ if (habbo.getHabboInfo().getGamePlayer() != null) {
+ habbo.getHabboInfo().getGamePlayer().reset();
+ }
}
habbo.getHabboInfo().setCurrentGame(null);
@@ -238,7 +240,10 @@ public abstract class Game implements Runnable {
if (this.room == null)
return;
- for (Map.Entry teamEntry : this.teams.entrySet()) {
+ THashMap teamsCopy = new THashMap<>();
+ teamsCopy.putAll(this.teams);
+
+ for (Map.Entry teamEntry : teamsCopy.entrySet()) {
Emulator.getThreading().run(new SaveScoreForTeam(teamEntry.getValue(), this));
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
index 1950c917..bfd82a59 100644
--- a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
+++ b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java
@@ -13,6 +13,7 @@ public class GamePlayer {
private int score;
+ private int wiredScore;
public GamePlayer(Habbo habbo, GameTeamColors teamColor) {
@@ -23,15 +24,23 @@ public class GamePlayer {
public void reset() {
this.score = 0;
+ this.wiredScore = 0;
}
-
public synchronized void addScore(int amount) {
+ addScore(amount, false);
+ }
+
+ public synchronized void addScore(int amount, boolean isWired) {
if (habbo.getHabboInfo().getGamePlayer() != null && this.habbo.getHabboInfo().getCurrentGame() != null && this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo) != null) {
this.score += amount;
if (this.score < 0) this.score = 0;
+ if(isWired && this.score > 0) {
+ this.wiredScore += amount;
+ }
+
WiredHandler.handle(WiredTriggerType.SCORE_ACHIEVED, this.habbo.getRoomUnit(), this.habbo.getHabboInfo().getCurrentRoom(), new Object[]{this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo).getTotalScore(), amount});
}
}
@@ -49,4 +58,8 @@ public class GamePlayer {
public int getScore() {
return this.score;
}
+
+ public int getScoreAchievementValue() {
+ return this.score - this.wiredScore;
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java
index 31a561b5..b2ee6dcf 100644
--- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java
+++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java
@@ -44,6 +44,7 @@ public class BattleBanzaiGame extends Game {
private final THashMap gameTiles;
private int tileCount;
private int countDown;
+ private int countDown2;
public BattleBanzaiGame(Room room) {
super(BattleBanzaiGameTeam.class, BattleBanzaiGamePlayer.class, room, true);
@@ -58,8 +59,12 @@ public class BattleBanzaiGame extends Game {
public void initialise() {
if (!this.state.equals(GameState.IDLE))
return;
-
+
+ /* The first countdown is activated for the first two seconds emitting only the blue light (second interaction),
+ the second, after another two seconds, completely activates the sphere (third interaction).
+ */
this.countDown = 3;
+ this.countDown2 = 2;
this.resetMap();
@@ -105,8 +110,15 @@ public class BattleBanzaiGame extends Game {
if (this.countDown == 0) {
for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) {
- item.setExtradata("2");
+ item.setExtradata("1");
this.room.updateItemState(item);
+ if(this.countDown2 > 0) {
+ this.countDown2--;
+ if(this.countDown2 == 0) {
+ item.setExtradata("2");
+ this.room.updateItemState(item);
+ }
+ }
}
}
@@ -166,7 +178,7 @@ public class BattleBanzaiGame extends Game {
for (GameTeam team : this.teams.values()) {
if (!singleTeamGame) {
for (GamePlayer player : team.getMembers()) {
- if (player.getScore() > 0) {
+ if (player.getScoreAchievementValue() > 0) {
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer"));
}
}
@@ -180,7 +192,7 @@ public class BattleBanzaiGame extends Game {
if (winningTeam != null) {
if (!singleTeamGame) {
for (GamePlayer player : winningTeam.getMembers()) {
- if (player.getScore() > 0) {
+ if (player.getScoreAchievementValue() > 0) {
this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose());
AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner"));
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java
index eb625350..642564d1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java
+++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java
@@ -287,9 +287,9 @@ public class FreezeGame extends Game {
players.addAll(team.getMembers());
for (GamePlayer p : players) {
- if (p.getScore() > 0) {
+ if (p.getScoreAchievementValue() > 0) {
if (team.equals(winningTeam)) {
- AchievementManager.progressAchievement(p.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FreezeWinner"), p.getScore());
+ AchievementManager.progressAchievement(p.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FreezeWinner"), p.getScoreAchievementValue());
this.room.sendComposer(new RoomUserActionComposer(p.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose());
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/Item.java b/src/main/java/com/eu/habbo/habbohotel/items/Item.java
index eb7316ff..11d19294 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/Item.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/Item.java
@@ -3,12 +3,14 @@ package com.eu.habbo.habbohotel.items;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.items.interactions.InteractionMultiHeight;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.messages.ISerialize;
+import com.eu.habbo.messages.ServerMessage;
import gnu.trove.list.array.TIntArrayList;
import java.sql.ResultSet;
import java.sql.SQLException;
-public class Item {
+public class Item implements ISerialize {
private int id;
private int spriteId;
@@ -36,6 +38,7 @@ public class Item {
private String clothingOnWalk;
private ItemInteraction interactionType;
+ private int rotations;
public Item(ResultSet set) throws SQLException {
this.load(set);
@@ -117,6 +120,13 @@ public class Item {
this.multiHeights = new double[0];
}
}
+
+ this.rotations = 4;
+
+ try {
+ this.rotations = set.getInt("rotations");
+ }
+ catch (SQLException ignored) { }
}
public int getId() {
@@ -220,4 +230,34 @@ public class Item {
}
public String getClothingOnWalk() { return clothingOnWalk; }
+
+ public int getRotations() {
+ return rotations;
+ }
+
+ @Override
+ public void serialize(ServerMessage message) {
+ message.appendString(this.type.code.toLowerCase());
+
+ if (type == FurnitureType.BADGE) {
+ message.appendString(this.customParams);
+ } else {
+ message.appendInt(this.spriteId);
+
+ if (this.getName().contains("wallpaper_single") || this.getName().contains("floor_single") || this.getName().contains("landscape_single")) {
+ message.appendString(this.name.split("_")[2]);
+ } else if (type == FurnitureType.ROBOT) {
+ message.appendString(this.customParams);
+ } else if (name.equalsIgnoreCase("poster")) {
+ message.appendString(this.customParams);
+ } else if (name.startsWith("SONG ")) {
+ message.appendString(this.customParams);
+ } else {
+ message.appendString("");
+ }
+
+ message.appendInt(1); // productCount
+ message.appendBoolean(false);
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
index 7fdc0202..f702d68c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java
@@ -141,6 +141,7 @@ public class ItemManager {
this.interactionsList.add(new ItemInteraction("puzzle_box", InteractionPuzzleBox.class));
this.interactionsList.add(new ItemInteraction("hopper", InteractionHopper.class));
this.interactionsList.add(new ItemInteraction("costume_hopper", InteractionCostumeHopper.class));
+ this.interactionsList.add(new ItemInteraction("effect_gate", InteractionEffectGate.class));
this.interactionsList.add(new ItemInteraction("club_hopper", InteractionHabboClubHopper.class));
this.interactionsList.add(new ItemInteraction("club_gate", InteractionHabboClubGate.class));
this.interactionsList.add(new ItemInteraction("club_teleporttile", InteractionHabboClubTeleportTile.class));
@@ -685,13 +686,14 @@ public class ItemManager {
}
public HabboItem createGift(String username, Item item, String extraData, int limitedStack, int limitedSells) {
- HabboItem gift = null;
- int userId = 0;
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(username);
+ int userId = 0;
+
if (habbo != null) {
userId = habbo.getHabboInfo().getId();
- } else {
+ }
+ else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT id FROM users WHERE username = ?")) {
statement.setString(1, username);
try (ResultSet set = statement.executeQuery()) {
@@ -704,6 +706,14 @@ public class ItemManager {
}
}
+ if(userId > 0) {
+ return createGift(userId, item, extraData, limitedStack, limitedSells);
+ }
+
+ return null;
+ }
+
+ public HabboItem createGift(int userId, Item item, String extraData, int limitedStack, int limitedSells) {
if (userId == 0)
return null;
@@ -712,26 +722,12 @@ public class ItemManager {
extraData = extraData.substring(0, 1000);
}
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO items (user_id, item_id, extra_data, limited_data) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
- statement.setInt(1, userId);
- statement.setInt(2, item.getId());
- statement.setString(3, extraData);
- statement.setString(4, limitedStack + ":" + limitedSells);
- statement.execute();
-
- try (ResultSet set = statement.getGeneratedKeys()) {
- if (set.next()) {
- gift = new InteractionGift(set.getInt(1), userId, item, extraData, limitedStack, limitedSells);
- }
- }
- } catch (SQLException e) {
- LOGGER.error("Caught SQL exception", e);
- }
+ HabboItem gift = this.createItem(userId, item, limitedStack, limitedSells, extraData);
if (gift != null) {
+ Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
if (habbo != null) {
habbo.getInventory().getItemsComponent().addItem(gift);
-
habbo.getClient().sendResponse(new AddHabboItemComposer(gift));
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
index 813ce782..ab6bf36e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java
@@ -52,7 +52,7 @@ public class InteractionBackgroundToner extends HabboItem {
@Override
public boolean isWalkable() {
- return false;
+ return this.getBaseItem().allowWalk();
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
index 70869154..af65156c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java
@@ -10,6 +10,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionHabboClub;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.users.UserClubComposer;
import com.eu.habbo.messages.outgoing.users.UserPermissionsComposer;
@@ -120,16 +121,10 @@ public class InteractionCrackable extends HabboItem {
// subscriptions are given immediately upon cracking
switch (rewardData.subscriptionType) {
case HABBO_CLUB:
- if (habbo.getHabboStats().getClubExpireTimestamp() <= Emulator.getIntUnixTimestamp())
- habbo.getHabboStats().setClubExpireTimestamp(Emulator.getIntUnixTimestamp());
-
- habbo.getHabboStats().setClubExpireTimestamp(habbo.getHabboStats().getClubExpireTimestamp() + (rewardData.subscriptionDuration * 86400));
- habbo.getClient().sendResponse(new UserPermissionsComposer(habbo));
- habbo.getClient().sendResponse(new UserClubComposer(habbo));
- habbo.getHabboStats().run();
+ habbo.getHabboStats().createSubscription(SubscriptionHabboClub.HABBO_CLUB, rewardData.subscriptionDuration * 86400);
break;
case BUILDERS_CLUB:
- habbo.alert("Builders club has not been implemented yet. Sorry!");
+ habbo.getHabboStats().createSubscription("BUILDERS_CLUB", rewardData.subscriptionDuration * 86400);
break;
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java
index d25a3cc8..9ef005bc 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java
@@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.items.interactions;
+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.RoomUnit;
@@ -78,4 +79,8 @@ public abstract class InteractionCustomValues extends HabboItem {
super.serializeExtradata(serverMessage);
}
+
+ public void onCustomValuesSaved(Room room, GameClient client) {
+
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
index 1db3a1d2..4860d0ff 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java
@@ -48,15 +48,17 @@ public class InteractionDefault extends HabboItem {
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation);
- for (RoomUnit unit : room.getRoomUnits()) {
- if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem()))
- continue; // If the unit was previously on the furni...
- if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore...
+ if(room.getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) {
+ for (RoomUnit unit : room.getRoomUnits()) {
+ if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem()))
+ continue; // If the unit was previously on the furni...
+ if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore...
- try {
- this.onWalkOff(unit, room, new Object[]{}); // the unit walked off!
- } catch (Exception ignored) {
+ try {
+ this.onWalkOff(unit, room, new Object[]{oldLocation, newLocation}); // the unit walked off!
+ } catch (Exception ignored) {
+ }
}
}
}
@@ -137,14 +139,22 @@ public class InteractionDefault extends HabboItem {
if (roomUnit != null) {
if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) {
+ int nextEffectM = 0;
+ int nextEffectF = 0;
+
if (objects != null && objects.length == 2) {
if (objects[0] instanceof RoomTile && objects[1] instanceof RoomTile) {
- RoomTile goalTile = (RoomTile) objects[1];
- HabboItem topItem = room.getTopItemAt(goalTile.x, goalTile.y);
+ RoomTile goalTile = (RoomTile) objects[0];
+ HabboItem topItem = room.getTopItemAt(goalTile.x, goalTile.y, (objects[0] != objects[1]) ? this : null);
if (topItem != null && (topItem.getBaseItem().getEffectM() == this.getBaseItem().getEffectM() || topItem.getBaseItem().getEffectF() == this.getBaseItem().getEffectF())) {
return;
}
+
+ if(topItem != null) {
+ nextEffectM = topItem.getBaseItem().getEffectM();
+ nextEffectF = topItem.getBaseItem().getEffectF();
+ }
}
}
@@ -154,12 +164,12 @@ public class InteractionDefault extends HabboItem {
if (habbo != null) {
if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
- room.giveEffect(habbo, 0, -1);
+ room.giveEffect(habbo, nextEffectM, -1);
return;
}
if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
- room.giveEffect(habbo, 0, -1);
+ room.giveEffect(habbo, nextEffectF, -1);
}
}
} else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) {
@@ -167,12 +177,12 @@ public class InteractionDefault extends HabboItem {
if (bot != null) {
if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) {
- room.giveEffect(roomUnit, 0, -1);
+ room.giveEffect(roomUnit, nextEffectM, -1);
return;
}
if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) {
- room.giveEffect(roomUnit, 0, -1);
+ room.giveEffect(roomUnit, nextEffectF, -1);
}
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java
new file mode 100644
index 00000000..0e6ad5d7
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java
@@ -0,0 +1,85 @@
+package com.eu.habbo.habbohotel.items.interactions;
+
+import com.eu.habbo.Emulator;
+import com.eu.habbo.habbohotel.gameclients.GameClient;
+import com.eu.habbo.habbohotel.items.Item;
+import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.threading.runnables.CloseGate;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class InteractionEffectGate extends InteractionDefault implements ConditionalGate {
+
+ // List of Habboween costumes according to http://www.habboxwiki.com/Costumes
+ private static final List defaultAllowedEnables = new ArrayList<>(Arrays.asList(
+ 114, // Strong Arms
+ 115, // Ringmaster Costume
+ 116, // Fly Head
+ 117, // Executioner Hood
+ 118, // Evil Clown Paint
+ 135 // Marionette
+ ));
+
+ public InteractionEffectGate(ResultSet set, Item baseItem) throws SQLException {
+ super(set, baseItem);
+ this.setExtradata("0");
+ }
+
+ public InteractionEffectGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
+ super(id, userId, item, extradata, limitedStack, limitedSells);
+ this.setExtradata("0");
+ }
+
+ @Override
+ public boolean isWalkable() {
+ return true;
+ }
+
+ @Override
+ public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
+ if (roomUnit == null || room == null)
+ return false;
+
+ String customparams = this.getBaseItem().getCustomParams().trim();
+
+ if (!customparams.isEmpty()) {
+ return Arrays.asList(customparams.split(";"))
+ .contains(Integer.valueOf(roomUnit.getEffectId()).toString());
+ }
+
+ return defaultAllowedEnables.contains(roomUnit.getEffectId());
+ }
+
+ @Override
+ public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
+ super.onWalkOn(roomUnit, room, objects);
+
+ if (this.canWalkOn(roomUnit, room, objects)) {
+ this.setExtradata("1");
+ room.updateItemState(this);
+ }
+ }
+
+ @Override
+ public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
+ super.onClick(client, room, objects);
+ }
+
+ @Override
+ public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
+ super.onWalkOff(roomUnit, room, objects);
+
+ Emulator.getThreading().run(new CloseGate(this, room), 1000);
+ }
+
+ @Override
+ public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
+
+ }
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
index cb8eb2ab..ac10dcc7 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java
@@ -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
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java
index 645c0d4e..b2255e2f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java
@@ -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 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);
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java
index 5c0b3422..f7ceb0e3 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
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.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredEffectType;
@@ -38,17 +39,21 @@ public class InteractionGate extends HabboItem {
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
- boolean isWired = (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE);
- if (client != null && !room.hasRights(client.getHabbo()) && !isWired)
+ boolean executedByWired = (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE);
+
+ if (client != null && !room.hasRights(client.getHabbo()) && !executedByWired)
return;
- if (!isWired && !room.getHabbosAt(this.getX(), this.getY()).isEmpty())
- return;
+ // If a Habbo is standing on a tile occupied by the gate, the gate shouldn't open/close
+ for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()))
+ if (room.hasHabbosAt(tile.x, tile.y))
+ return;
+ // Gate closed = 0, open = 1
if (this.getExtradata().length() == 0)
this.setExtradata("0");
- this.setExtradata((Integer.valueOf(this.getExtradata()) + 1) % 2 + "");
+ this.setExtradata((Integer.parseInt(this.getExtradata()) + 1) % 2 + "");
room.updateTile(room.getLayout().getTile(this.getX(), this.getY()));
this.needsUpdate(true);
room.updateItemState(this);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java
index 667c5f44..b4374f86 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java
@@ -6,12 +6,18 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.messages.ServerMessage;
+import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InteractionGuildFurni extends InteractionDefault {
private int guildId;
+ private static final THashSet ROTATION_8_ITEMS = new THashSet() {
+ {
+ this.add("gld_wall_tall");
+ }
+ };
public InteractionGuildFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -23,6 +29,14 @@ public class InteractionGuildFurni extends InteractionDefault {
this.guildId = 0;
}
+ @Override
+ public int getMaximumRotations() {
+ if(ROTATION_8_ITEMS.stream().anyMatch(x -> x.equalsIgnoreCase(this.getBaseItem().getName()))) {
+ return 8;
+ }
+ return this.getBaseItem().getRotations();
+ }
+
@Override
public void serializeExtradata(ServerMessage serverMessage) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guildId);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java
index 176ae78d..41290215 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
+import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
@@ -13,7 +14,7 @@ import com.eu.habbo.threading.runnables.CloseGate;
import java.sql.ResultSet;
import java.sql.SQLException;
-public class InteractionGuildGate extends InteractionGuildFurni {
+public class InteractionGuildGate extends InteractionGuildFurni implements ConditionalGate {
public InteractionGuildGate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
@@ -61,4 +62,9 @@ public class InteractionGuildGate extends InteractionGuildFurni {
this.setExtradata("0");
room.updateItemState(this);
}
+
+ @Override
+ public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
+
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java
index f9aa57dc..f356d4d3 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java
@@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
+import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
@@ -12,7 +13,7 @@ import com.eu.habbo.threading.runnables.CloseGate;
import java.sql.ResultSet;
import java.sql.SQLException;
-public class InteractionHabboClubGate extends InteractionDefault {
+public class InteractionHabboClubGate extends InteractionDefault implements ConditionalGate {
public InteractionHabboClubGate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
@@ -42,14 +43,6 @@ public class InteractionHabboClubGate extends InteractionDefault {
if (this.canWalkOn(roomUnit, room, objects)) {
this.setExtradata("1");
room.updateItemState(this);
- } else {
- Habbo habbo = room.getHabbo(roomUnit);
-
- if (habbo != null) {
- habbo.getClient().sendResponse(new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC));
- }
-
- roomUnit.setGoalLocation(roomUnit.getCurrentLocation());
}
}
@@ -70,4 +63,14 @@ public class InteractionHabboClubGate extends InteractionDefault {
Emulator.getThreading().run(new CloseGate(this, room), 1000);
}
+
+ @Override
+ public void onRejected(RoomUnit roomUnit, Room room, Object[] objects) {
+ if (roomUnit == null || room == null)
+ return;
+
+ room.getHabbo(roomUnit).getClient().sendResponse(
+ new CustomNotificationComposer(CustomNotificationComposer.GATE_NO_HC)
+ );
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java
index 2901a7b9..f9c304a4 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java
@@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer;
import com.eu.habbo.messages.outgoing.users.UserDataComposer;
@@ -22,6 +23,11 @@ public class InteractionMannequin extends HabboItem {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+ @Override
+ public int getMaximumRotations() {
+ return 8;
+ }
+
@Override
public void serializeExtradata(ServerMessage serverMessage) {
serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0));
@@ -60,26 +66,39 @@ public class InteractionMannequin extends HabboItem {
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
- String[] lookCode = this.getExtradata().split(":")[1].split("\\.");
+ String[] data = this.getExtradata().split(":");
- StringBuilder look = new StringBuilder();
- for (String part : client.getHabbo().getHabboInfo().getLook().split("\\.")) {
- String type = part.split("-")[0];
+ if(data.length < 2)
+ return;
- boolean found = false;
- for (String s : lookCode) {
- if (s.contains(type)) {
- found = true;
- look.append(s).append(".");
- }
- }
+ String gender = data[0];
+ String figure = data[1];
- if (!found) {
- look.append(part).append(".");
- }
+ if (gender.isEmpty() || figure.isEmpty() || (!gender.equalsIgnoreCase("m") && !gender.equalsIgnoreCase("f")) || !client.getHabbo().getHabboInfo().getGender().name().equalsIgnoreCase(gender))
+ return;
+
+ String newFigure = "";
+
+ for (String playerFigurePart : client.getHabbo().getHabboInfo().getLook().split("\\.")) {
+ if (!playerFigurePart.startsWith("ch") && !playerFigurePart.startsWith("lg"))
+ newFigure += playerFigurePart + ".";
}
- client.getHabbo().getHabboInfo().setLook(look.substring(0, look.length() - 1));
+ String newFigureParts = figure;
+
+ for (String newFigurePart : newFigureParts.split("\\.")) {
+ if (newFigurePart.startsWith("hd"))
+ newFigureParts = newFigureParts.replace(newFigurePart, "");
+ }
+
+ if (newFigureParts.equals("")) return;
+
+ String newLook = newFigure + newFigureParts;
+
+ if (newLook.length() > 512)
+ return;
+
+ client.getHabbo().getHabboInfo().setLook(ClothingValidationManager.VALIDATE_ON_MANNEQUIN ? ClothingValidationManager.validateLook(client.getHabbo(), newLook, client.getHabbo().getHabboInfo().getGender().name()) : newLook);
room.sendComposer(new RoomUserDataComposer(client.getHabbo()).compose());
client.sendResponse(new UserDataComposer(client.getHabbo()));
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java
index 765b6e3b..47cba012 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java
@@ -15,6 +15,7 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -68,39 +69,39 @@ public class InteractionMultiHeight extends HabboItem {
this.setExtradata("0");
if (this.getBaseItem().getMultiHeights().length > 0) {
- this.setExtradata("" + (Integer.valueOf(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
+ this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length));
this.needsUpdate(true);
room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()));
room.updateItemState(this);
//room.sendComposer(new UpdateStackHeightComposer(this.getX(), this.getY(), this.getBaseItem().getMultiHeights()[Integer.valueOf(this.getExtradata())] * 256.0D).compose());
}
+ }
+ }
+ }
- if (this.isWalkable()) {
- List unitsOnItem = new ArrayList<>();
- unitsOnItem.addAll(room.getHabbosOnItem(this).stream().map(Habbo::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
- unitsOnItem.addAll(room.getBotsOnItem(this).stream().map(Bot::getRoomUnit).filter(Objects::nonNull).collect(Collectors.toList()));
+ public void updateUnitsOnItem(Room room) {
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation());
- THashSet updatedUnits = new THashSet<>();
- for (RoomUnit unit : unitsOnItem) {
- if (unit.hasStatus(RoomUnitStatus.MOVE))
- continue;
+ for(RoomTile tile : occupiedTiles) {
+ Collection unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.x, tile.y));
- if (this.getBaseItem().getMultiHeights().length >= 0) {
- if (this.getBaseItem().allowSit()) {
- unit.setStatus(RoomUnitStatus.SIT, this.getBaseItem().getMultiHeights()[(this.getExtradata().isEmpty() ? 0 : Integer.valueOf(this.getExtradata()) % (this.getBaseItem().getMultiHeights().length))] * 1.0D + "");
- } else {
- unit.setZ(unit.getCurrentLocation().getStackHeight());
- unit.setPreviousLocationZ(unit.getZ());
- }
- }
+ THashSet updatedUnits = new THashSet<>();
+ for (RoomUnit unit : unitsOnItem) {
+ if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoal() != tile)
+ continue;
- updatedUnits.add(unit);
- }
-
- room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
+ if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) {
+ unit.sitUpdate = true;
+ unit.statusUpdate(true);
+ } else {
+ unit.setZ(unit.getCurrentLocation().getStackHeight());
+ unit.setPreviousLocationZ(unit.getZ());
+ unit.statusUpdate(true);
}
}
}
+
+ //room.sendComposer(new RoomUserStatusComposer(updatedUnits, true).compose());
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
index fcc9522a..29a7c0ac 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java
@@ -1,8 +1,21 @@
package com.eu.habbo.habbohotel.items.interactions;
+import com.eu.habbo.Emulator;
+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.RoomTile;
+import com.eu.habbo.habbohotel.rooms.RoomTileState;
+import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.WiredEffectType;
+import com.eu.habbo.messages.outgoing.rooms.items.ItemExtraDataComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer;
+import com.eu.habbo.messages.outgoing.rooms.items.RoomFloorItemsComposer;
+import gnu.trove.TCollections;
+import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.THashMap;
+import gnu.trove.map.hash.TIntObjectHashMap;
+import gnu.trove.set.hash.THashSet;
import java.awt.*;
import java.sql.ResultSet;
@@ -25,25 +38,122 @@ public class InteractionMuteArea extends InteractionCustomValues {
{
this.put("tilesBack", "0");
}
+
+ {
+ this.put("state", "0");
+ }
};
+ private THashSet tiles;
+
public InteractionMuteArea(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem, defaultValues);
+ tiles = new THashSet<>();
}
public InteractionMuteArea(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues);
+ tiles = new THashSet<>();
+ }
+
+ @Override
+ public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
+ super.onClick(client, room, objects);
+
+ if((objects.length >= 2 && objects[1] instanceof WiredEffectType) || (client != null && room.hasRights(client.getHabbo()))) {
+ this.values.put("state", this.values.get("state").equals("0") ? "1" : "0");
+ room.sendComposer(new ItemExtraDataComposer(this).compose());
+ }
+ }
+
+ @Override
+ public void onPlace(Room room) {
+ super.onPlace(room);
+ this.regenAffectedTiles(room);
+ }
+
+ @Override
+ public void onPickUp(Room room) {
+ super.onPickUp(room);
+ this.tiles.clear();
+ }
+
+ @Override
+ public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
+ super.onMove(room, oldLocation, newLocation);
+ this.regenAffectedTiles(room);
}
public boolean inSquare(RoomTile location) {
- try {
+ Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
+
+ if(!this.values.get("state").equals("1"))
+ return false;
+
+ if(room != null && this.tiles.size() == 0) {
+ regenAffectedTiles(room);
+ }
+
+ return this.tiles.contains(location);
+
+ /*try {
return new Rectangle(
- this.getX() - Integer.valueOf(this.values.get("tilesBack")),
+ this.getX() - Integer.parseInt(this.values.get("tilesBack")),
this.getY() + Integer.valueOf(this.values.get("tilesLeft")) - (Integer.valueOf(this.values.get("tilesLeft")) + Integer.valueOf(this.values.get("tilesRight"))),
Integer.valueOf(this.values.get("tilesLeft")) + Integer.valueOf(this.values.get("tilesRight")) + 1,
Integer.valueOf(this.values.get("tilesFront")) + Integer.valueOf(this.values.get("tilesBack")) + 1).contains(location.x, location.y);
} catch (Exception e) {
return false;
+ }*/
+ }
+
+ private void regenAffectedTiles(Room room) {
+ int minX = Math.max(0, this.getX() - Integer.parseInt(this.values.get("tilesBack")));
+ int minY = Math.max(0, this.getY() - Integer.parseInt(this.values.get("tilesRight")));
+ int maxX = Math.min(room.getLayout().getMapSizeX(), this.getX() + Integer.parseInt(this.values.get("tilesFront")));
+ int maxY = Math.min(room.getLayout().getMapSizeY(), this.getY() + Integer.parseInt(this.values.get("tilesLeft")));
+
+ this.tiles.clear();
+
+ for(int x = minX; x <= maxX; x++) {
+ for(int y = minY; y <= maxY; y++) {
+ RoomTile tile = room.getLayout().getTile((short)x, (short)y);
+ if(tile != null && tile.state != RoomTileState.INVALID)
+ this.tiles.add(tile);
+ }
+ }
+ }
+
+ @Override
+ public void onCustomValuesSaved(Room room, GameClient client) {
+ super.onCustomValuesSaved(room, client);
+
+ this.regenAffectedTiles(room);
+
+ // show the effect
+ Item effectItem = Emulator.getGameEnvironment().getItemManager().getItem("mutearea_sign2");
+
+ if(effectItem != null) {
+ TIntObjectMap ownerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0));
+ ownerNames.put(-1, "System");
+ THashSet items = new THashSet<>();
+
+ int id = 0;
+ for(RoomTile tile : this.tiles) {
+ id--;
+ HabboItem item = new InteractionDefault(id, -1, effectItem, "1", 0, 0);
+ item.setX(tile.x);
+ item.setY(tile.y);
+ item.setZ(tile.relativeHeight());
+ items.add(item);
+ }
+
+ client.sendResponse(new RoomFloorItemsComposer(ownerNames, items));
+ Emulator.getThreading().run(() -> {
+ for(HabboItem item : items) {
+ client.sendResponse(new RemoveFloorItemComposer(item, true));
+ }
+ }, 3000);
}
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
index 5b3cdb75..a63dcad8 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java
@@ -1,33 +1,34 @@
package com.eu.habbo.habbohotel.items.interactions;
-import com.eu.habbo.Emulator;
-import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.gameclients.GameClient;
+import com.eu.habbo.habbohotel.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.pets.HorsePet;
import com.eu.habbo.habbohotel.pets.Pet;
-import com.eu.habbo.habbohotel.pets.PetTasks;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
-import com.eu.habbo.habbohotel.rooms.RoomUserRotation;
+import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.ServerMessage;
-import com.eu.habbo.threading.runnables.HabboItemNewState;
+import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Objects;
+
+public class InteractionObstacle extends HabboItem implements ICycleable {
+
+ private THashSet middleTiles;
-public class InteractionObstacle extends HabboItem {
public InteractionObstacle(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
+ this.middleTiles = new THashSet<>();
}
public InteractionObstacle(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
this.setExtradata("0");
+ this.middleTiles = new THashSet<>();
}
@Override
@@ -40,20 +41,12 @@ public class InteractionObstacle extends HabboItem {
@Override
public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) {
- Pet pet = room.getPet(roomUnit);
-
- if (pet instanceof HorsePet) {
- HorsePet horsePet = (HorsePet) pet;
-
- return horsePet.getRider() != null;
- }
-
- return false;
+ return true;
}
@Override
public boolean isWalkable() {
- return false;
+ return true;
}
@Override
@@ -63,36 +56,32 @@ public class InteractionObstacle extends HabboItem {
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
- Habbo habbo = room.getHabbo(roomUnit);
+ /*Pet pet = room.getPet(roomUnit);
- if (habbo != null) {
- Pet pet = room.getPet(roomUnit);
+ if (pet instanceof HorsePet && ((HorsePet) pet).getRider() != null) {
+ if (pet.getTask() != null && pet.getTask().equals(PetTasks.RIDE)) {
+ if (pet.getRoomUnit().hasStatus(RoomUnitStatus.JUMP)) {
+ pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
+ Emulator.getThreading().run(new HabboItemNewState(this, room, "0"), 2000);
+ } else {
+ int state = 0;
+ for (int i = 0; i < 2; i++) {
+ state = Emulator.getRandom().nextInt(4) + 1;
- if (pet instanceof HorsePet && ((HorsePet) pet).getRider() != null) {
- if (pet.getTask() != null && pet.getTask().equals(PetTasks.RIDE)) {
- if (pet.getRoomUnit().hasStatus(RoomUnitStatus.JUMP)) {
- pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP);
- Emulator.getThreading().run(new HabboItemNewState(this, room, "0"), 2000);
- } else {
- int state = 0;
- for (int i = 0; i < 2; i++) {
- state = Emulator.getRandom().nextInt(4) + 1;
-
- if (state == 4)
- break;
- }
-
- this.setExtradata(state + "");
- pet.getRoomUnit().setStatus(RoomUnitStatus.JUMP, "0");
-
- AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("HorseConsecutiveJumpsCount"));
- AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("HorseJumping"));
+ if (state == 4)
+ break;
}
- room.updateItemState(this);
+ this.setExtradata(state + "");
+ pet.getRoomUnit().setStatus(RoomUnitStatus.JUMP, "0");
+
+ AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("HorseConsecutiveJumpsCount"));
+ AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("HorseJumping"));
}
+
+ room.updateItemState(this);
}
- }
+ }*/
}
@Override
@@ -138,4 +127,70 @@ public class InteractionObstacle extends HabboItem {
}
}
}
+
+ @Override
+ public void onPlace(Room room) {
+ super.onPlace(room);
+ this.calculateMiddleTiles(room);
+ }
+
+ @Override
+ public void onPickUp(Room room) {
+ super.onPickUp(room);
+ middleTiles.clear();
+ }
+
+ @Override
+ public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
+ super.onMove(room, oldLocation, newLocation);
+ this.calculateMiddleTiles(room);
+ }
+
+ private void calculateMiddleTiles(Room room) {
+ middleTiles.clear();
+
+ if(this.getRotation() == 2) {
+ middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), this.getY()));
+ middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), (short)(this.getY() + 1)));
+ }
+ else if(this.getRotation() == 4) {
+ middleTiles.add(room.getLayout().getTile(this.getX(), (short)(this.getY() + 1)));
+ middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), (short)(this.getY() + 1)));
+ }
+ }
+
+ @Override
+ public RoomTileState getOverrideTileState(RoomTile tile, Room room) {
+ if(this.middleTiles.contains(tile))
+ return RoomTileState.BLOCKED;
+
+ return null;
+ }
+
+ @Override
+ public void cycle(Room room) {
+ if(this.middleTiles.size() == 0) {
+ this.calculateMiddleTiles(room);
+ }
+
+ for(RoomTile tile : this.middleTiles) {
+ for(RoomUnit unit : tile.getUnits()) {
+ if(unit.getPath().size() == 0 && !unit.hasStatus(RoomUnitStatus.MOVE)) {
+ if(unit.getBodyRotation().getValue() != this.getRotation() && Objects.requireNonNull(unit.getBodyRotation().getOpposite()).getValue() != this.getRotation())
+ continue;
+
+ RoomTile tileInfront = room.getLayout().getTileInFront(unit.getCurrentLocation(), unit.getBodyRotation().getValue());
+ if(tileInfront.state != RoomTileState.INVALID && tileInfront.state != RoomTileState.BLOCKED && room.getRoomUnitsAt(tileInfront).size() == 0) {
+ unit.setGoalLocation(tileInfront);
+ }
+ else {
+ RoomTile tileBehind = room.getLayout().getTileInFront(unit.getCurrentLocation(), Objects.requireNonNull(unit.getBodyRotation().getOpposite()).getValue());
+ if(tileBehind.state != RoomTileState.INVALID && tileBehind.state != RoomTileState.BLOCKED && room.getRoomUnitsAt(tileBehind).size() == 0) {
+ unit.setGoalLocation(tileBehind);
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
index 844b042e..6a26e6cb 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java
@@ -7,9 +7,14 @@ import com.eu.habbo.habbohotel.rooms.Room;
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.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.rooms.users.RoomUserWalkEvent;
import com.eu.habbo.messages.outgoing.rooms.items.ItemIntStateComposer;
import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -17,6 +22,8 @@ import java.util.ArrayList;
import java.util.List;
public class InteractionOneWayGate extends HabboItem {
+ private static final Logger LOGGER = LoggerFactory.getLogger(InteractionOneWayGate.class);
+
private boolean walkable = false;
public InteractionOneWayGate(ResultSet set, Item baseItem) throws SQLException {
@@ -74,7 +81,6 @@ public class InteractionOneWayGate extends HabboItem {
if (unit == null)
return;
-
if (tileInfront.x == unit.getX() && tileInfront.y == unit.getY()) {
if (!currentLocation.hasUnits()) {
List onSuccess = new ArrayList();
@@ -86,6 +92,8 @@ public class InteractionOneWayGate extends HabboItem {
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4);
unit.setGoalLocation(tile);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onFail, onFail));
+
+ Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, unit, room, new Object[]{this}), 500);
});
onFail.add(() -> {
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java
index 0eee202b..06d19289 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java
@@ -8,12 +8,13 @@ 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.messages.outgoing.rooms.items.ItemStateComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
-public class InteractionPressurePlate extends HabboItem {
+public class InteractionPressurePlate extends InteractionDefault {
public InteractionPressurePlate(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.setExtradata("0");
@@ -39,14 +40,6 @@ public class InteractionPressurePlate extends HabboItem {
super.onClick(client, room, objects);
}
- @Override
- public void serializeExtradata(ServerMessage serverMessage) {
- serverMessage.appendInt((this.isLimited() ? 256 : 0));
- serverMessage.appendString(this.getExtradata());
-
- super.serializeExtradata(serverMessage);
- }
-
@Override
public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
@@ -99,7 +92,7 @@ public class InteractionPressurePlate extends HabboItem {
}
this.setExtradata(occupied ? "1" : "0");
- room.updateItem(this);
+ room.updateItemState(this);
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java
index 3cd88425..a8d0db0e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java
@@ -50,7 +50,7 @@ public abstract class InteractionPushable extends InteractionDefault {
if (this.currentThread != null)
this.currentThread.dead = true;
- this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity);
+ this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity, false);
Emulator.getThreading().run(this.currentThread, 0);
}
}
@@ -69,7 +69,7 @@ public abstract class InteractionPushable extends InteractionDefault {
if (this.currentThread != null)
this.currentThread.dead = true;
- this.currentThread = new KickBallAction(this, room, client.getHabbo().getRoomUnit(), direction, velocity);
+ this.currentThread = new KickBallAction(this, room, client.getHabbo().getRoomUnit(), direction, velocity, false);
Emulator.getThreading().run(this.currentThread, 0);
}
}
@@ -80,6 +80,7 @@ public abstract class InteractionPushable extends InteractionDefault {
super.onWalkOn(roomUnit, room, objects);
int velocity;
+ boolean isDrag = false;
RoomUserRotation direction;
if (this.getX() == roomUnit.getGoal().x && this.getY() == roomUnit.getGoal().y) //User clicked on the tile the ball is on, they want to kick it
@@ -92,13 +93,14 @@ public abstract class InteractionPushable extends InteractionDefault {
velocity = this.getDragVelocity(roomUnit, room);
direction = this.getDragDirection(roomUnit, room);
this.onDrag(room, roomUnit, velocity, direction);
+ isDrag = true;
}
if (velocity > 0) {
if (this.currentThread != null)
this.currentThread.dead = true;
- this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity);
+ this.currentThread = new KickBallAction(this, room, roomUnit, direction, velocity, isDrag);
Emulator.getThreading().run(this.currentThread, 0);
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java
index 69d7fe3a..42813714 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java
@@ -93,7 +93,7 @@ public class InteractionTeleport extends HabboItem {
// set state 1 and walk on item
this.roomUnitID = unit.getId();
this.setExtradata("1");
- room.updateItem(this);
+ room.updateItemState(this);
unit.setGoalLocation(infrontTile);
List onSuccess = new ArrayList();
@@ -111,7 +111,7 @@ public class InteractionTeleport extends HabboItem {
walkable = this.getBaseItem().allowWalk();
room.updateTile(currentLocation);
this.setExtradata("0");
- room.updateItem(this);
+ room.updateItemState(this);
this.roomUnitID = -1;
unit.removeOverrideTile(currentLocation);
unit.setCanLeaveRoomByDoor(true);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java
index 791109a4..80f2c39c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java
@@ -13,4 +13,9 @@ public class InteractionTrophy extends InteractionDefault {
public InteractionTrophy(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
}
+
+ @Override
+ public boolean allowWiredResetState() {
+ return false;
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java
index be0f5cba..63a32a1a 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java
@@ -7,6 +7,8 @@ import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
@@ -34,8 +36,12 @@ public class InteractionVendingMachine extends HabboItem {
}
public THashSet getActivatorTiles(Room room) {
- THashSet tiles = new THashSet();
- tiles.add(getSquareInFront(room.getLayout(), this));
+ THashSet tiles = new THashSet<>();
+ RoomTile tileInFront = getSquareInFront(room.getLayout(), this);
+
+ if (tileInFront != null)
+ tiles.add(tileInFront);
+
tiles.add(room.getLayout().getTile(this.getX(), this.getY()));
return tiles;
}
@@ -71,7 +77,13 @@ public class InteractionVendingMachine extends HabboItem {
this.setExtradata("1");
room.updateItem(this);
- if(!unit.isWalking()) {
+ try {
+ super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if(!unit.isWalking() && !unit.hasStatus(RoomUnitStatus.SIT) && !unit.hasStatus(RoomUnitStatus.LAY)) {
this.rotateToMachine(room, unit);
}
@@ -94,8 +106,6 @@ public class InteractionVendingMachine extends HabboItem {
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
- super.onClick(client, room, objects);
-
if (client == null) {
return;
}
@@ -118,7 +128,7 @@ public class InteractionVendingMachine extends HabboItem {
if(!inActivatorSpace) {
RoomTile tileToWalkTo = null;
for(RoomTile tile : activatorTiles) {
- if(room.getLayout().tileWalkable(tile.x, tile.y) && (tileToWalkTo == null || tileToWalkTo.distance(unit.getCurrentLocation()) > tile.distance(unit.getCurrentLocation()))) {
+ if((tile.state == RoomTileState.OPEN || tile.state == RoomTileState.SIT) && (tileToWalkTo == null || tileToWalkTo.distance(unit.getCurrentLocation()) > tile.distance(unit.getCurrentLocation()))) {
tileToWalkTo = tile;
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java
index 0332c717..4b283da1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.items.interactions;
import com.eu.habbo.Emulator;
+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;
@@ -13,7 +14,7 @@ import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
-public class InteractionWaterItem extends InteractionDefault {
+public class InteractionWaterItem extends InteractionMultiHeight {
public InteractionWaterItem(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@@ -30,15 +31,22 @@ public class InteractionWaterItem extends InteractionDefault {
@Override
public void onPickUp(Room room) {
+ super.onPickUp(room);
this.setExtradata("0");
this.needsUpdate(true);
}
@Override
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
+ super.onMove(room, oldLocation, newLocation);
this.update();
}
+ @Override
+ public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
+ super.onClick(client, room, new Object[] { });
+ }
+
public void update() {
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
@@ -75,7 +83,7 @@ public class InteractionWaterItem extends InteractionDefault {
if (!this.getExtradata().equals(updatedData)) {
this.setExtradata(updatedData);
this.needsUpdate(true);
- room.updateItem(this);
+ room.updateItemState(this);
}
}
@@ -83,9 +91,4 @@ public class InteractionWaterItem extends InteractionDefault {
public boolean allowWiredResetState() {
return false;
}
-
- @Override
- public boolean canToggle(Habbo habbo, Room room) {
- return false;
- }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
index a465367c..c19b1ec9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java
@@ -15,7 +15,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-public abstract class InteractionWired extends HabboItem {
+public abstract class InteractionWired extends InteractionDefault {
private static final Logger LOGGER = LoggerFactory.getLogger(InteractionWired.class);
private long cooldown;
@@ -37,25 +37,6 @@ public abstract class InteractionWired extends HabboItem {
public abstract void loadWiredData(ResultSet set, Room room) throws SQLException;
- @Override
- public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
- super.onWalkOn(roomUnit, room, objects);
- }
-
- @Override
- public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
- super.onWalkOff(roomUnit, room, objects);
- }
-
-
- @Override
- public void serializeExtradata(ServerMessage serverMessage) {
- serverMessage.appendInt((this.isLimited() ? 256 : 0));
- serverMessage.appendString(this.getExtradata());
-
- super.serializeExtradata(serverMessage);
- }
-
@Override
public void run() {
if (this.needsUpdate()) {
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
index d8c7ed41..7bf21fe1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java
@@ -41,21 +41,6 @@ public abstract class InteractionWiredCondition extends InteractionWired {
}
}
- @Override
- public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
public abstract WiredConditionType getType();
public abstract boolean saveData(ClientMessage packet);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
index a6ae8ab4..59da2b6f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java
@@ -6,6 +6,7 @@ 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.messages.ClientMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer;
import java.sql.ResultSet;
@@ -42,22 +43,7 @@ public abstract class InteractionWiredEffect extends InteractionWired {
}
}
- @Override
- public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- public abstract boolean saveData(ClientMessage packet, GameClient gameClient);
+ public abstract boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException;
public int getDelay() {
return this.delay;
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
index 9708c565..8fb95dd4 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java
@@ -6,6 +6,9 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.wired.WiredEffectType;
+import com.eu.habbo.habbohotel.wired.WiredHandler;
+import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreClearType;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreRow;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreScoreType;
@@ -78,6 +81,9 @@ public class InteractionWiredHighscore extends HabboItem {
@Override
public void onClick(GameClient client, Room room, Object[] objects) throws Exception {
+ if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType)))
+ return;
+
if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) {
this.setExtradata("0");
}
@@ -89,6 +95,10 @@ public class InteractionWiredHighscore extends HabboItem {
} catch (Exception e) {
LOGGER.error("Caught exception", e);
}
+
+ if(client != null && !(objects.length >= 2 && objects[1] instanceof WiredEffectType)) {
+ WiredHandler.handle(WiredTriggerType.STATE_CHANGED, client.getHabbo().getRoomUnit(), room, new Object[]{this});
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
index 30ed0565..c0bbaabb 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java
@@ -42,21 +42,6 @@ public abstract class InteractionWiredTrigger extends InteractionWired {
}
}
- @Override
- public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
- @Override
- public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
-
- }
-
public abstract WiredTriggerType getType();
public abstract boolean saveData(ClientMessage packet);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
index 6197b017..bb868c6d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java
@@ -4,6 +4,7 @@ import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.games.Game;
import com.eu.habbo.habbohotel.games.GameState;
+import com.eu.habbo.habbohotel.games.wired.WiredGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.Room;
@@ -13,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;
@@ -62,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;
}
@@ -98,11 +100,15 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
}
public void endGame(Room room) {
+ endGame(room, false);
+ }
+
+ public void endGame(Room room, boolean isStart) {
this.isRunning = false;
this.isPaused = false;
for (Game game : room.getGames()) {
- if (!game.getState().equals(GameState.IDLE)) {
+ if (!game.getState().equals(GameState.IDLE) && !(isStart && game instanceof WiredGame)) {
game.onEnd();
game.stop();
}
@@ -144,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
@@ -226,7 +205,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable {
return;
boolean wasPaused = this.isPaused;
- this.endGame(room);
+ this.endGame(room, true);
if(wasPaused) {
WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{});
@@ -243,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)))
@@ -266,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 {
@@ -280,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);
}
}
@@ -345,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;
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
index 067f1056..98a627fe 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java
@@ -55,18 +55,18 @@ public class InteractionBattleBanzaiTeleporter extends HabboItem {
@Override
public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception {
super.onWalkOn(roomUnit, room, objects);
- HabboItem target = room.getRoomSpecialTypes().getRandomTeleporter(this.getBaseItem(), this);
- if (target == null) return;
+ if(objects.length < 3) {
+ HabboItem target = room.getRoomSpecialTypes().getRandomTeleporter(null, this);
+ if (target == null) return;
- this.setExtradata("1");
- roomUnit.removeStatus(RoomUnitStatus.MOVE);
- target.setExtradata("1");
- room.updateItem(this);
- room.updateItem(target);
- roomUnit.setGoalLocation(room.getLayout().getTile(roomUnit.getX(), roomUnit.getY()));
- roomUnit.setCanWalk(false);
- Emulator.getThreading().run(new BanzaiRandomTeleport(this, target, roomUnit, room), 1000);
+ this.setExtradata("1");
+ room.updateItemState(this);
+ roomUnit.removeStatus(RoomUnitStatus.MOVE);
+ roomUnit.setGoalLocation(roomUnit.getCurrentLocation());
+ roomUnit.setCanWalk(false);
+ Emulator.getThreading().run(new BanzaiRandomTeleport(this, target, roomUnit, room), 500);
+ }
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
index 482a3d96..f64b0ade 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java
@@ -1,15 +1,13 @@
package com.eu.habbo.habbohotel.items.interactions.games.football;
+import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.games.football.FootballGame;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionPushable;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTeamItem;
import com.eu.habbo.habbohotel.items.interactions.games.football.goals.InteractionFootballGoal;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomTile;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
-import com.eu.habbo.habbohotel.rooms.RoomUserRotation;
+import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer;
import com.eu.habbo.util.pathfinding.Rotation;
@@ -31,15 +29,21 @@ public class InteractionFootball extends InteractionPushable {
@Override
public int getWalkOnVelocity(RoomUnit roomUnit, Room room) {
- if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2)
+ if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2 && this.getExtradata().equals("1"))
return 0;
- return 6;
+ if (roomUnit.getPath().size() == 0 && roomUnit.tilesWalked() == 1)
+ return 6;
+
+ return 1;
}
@Override
public int getWalkOffVelocity(RoomUnit roomUnit, Room room) {
- return 6;
+ if (roomUnit.getPath().size() == 0 && roomUnit.tilesWalked() == 0)
+ return 6;
+
+ return 1;
}
@Override
@@ -79,8 +83,17 @@ public class InteractionFootball extends InteractionPushable {
@Override
public int getNextRollDelay(int currentStep, int totalSteps) {
- int t = 2500;
- return (totalSteps == 1) ? 500 : 100 * ((t = t / t - 1) * t * t * t * t + 1) + (currentStep * 100);
+
+ if(totalSteps > 4) {
+ if(currentStep <= 4) {
+ return 125;
+ }
+ }
+
+ return 500;
+
+ /*int t = 2500;
+ return (totalSteps == 1) ? 500 : 100 * ((t = t / t - 1) * t * t * t * t + 1) + (currentStep * 100);*/
}
@Override
@@ -136,9 +149,9 @@ public class InteractionFootball extends InteractionPushable {
@Override
public boolean validMove(Room room, RoomTile from, RoomTile to) {
- if (to == null) return false;
+ if (to == null || to.state == RoomTileState.INVALID) return false;
HabboItem topItem = room.getTopItemAt(to.x, to.y, this);
- return !(!room.getLayout().tileWalkable(to.x, to.y) || (topItem != null && (!topItem.getBaseItem().allowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay())));
+ return (topItem == null || topItem.getBaseItem().allowStack());
}
//Events
@@ -176,8 +189,11 @@ public class InteractionFootball extends InteractionPushable {
game.onScore(kicker, color);
}
- this.setExtradata(nextRoll <= 200 ? "8" : (nextRoll <= 250 ? "7" : (nextRoll <= 300 ? "6" : (nextRoll <= 350 ? "5" : (nextRoll <= 400 ? "4" : (nextRoll <= 450 ? "3" : (nextRoll <= 500 ? "2" : "1")))))));
+ this.setExtradata(Math.abs(currentStep - (totalSteps + 1)) + "");
room.sendComposer(new ItemStateComposer(this).compose());
+
+ /*this.setExtradata(nextRoll <= 200 ? "8" : (nextRoll <= 250 ? "7" : (nextRoll <= 300 ? "6" : (nextRoll <= 350 ? "5" : (nextRoll <= 400 ? "4" : (nextRoll <= 450 ? "3" : (nextRoll <= 500 ? "2" : "1")))))));
+ room.sendComposer(new ItemStateComposer(this).compose());*/
}
@Override
@@ -194,7 +210,7 @@ public class InteractionFootball extends InteractionPushable {
@Override
public boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) {
HabboItem topItem = room.getTopItemAt(from.x, from.y, this);
- return !(room.hasHabbosAt(to.x, to.y) || (topItem != null && topItem.getBaseItem().getName().startsWith("fball_goal_") && currentStep != 1));
+ return !((Emulator.getRandom().nextInt(10) >= 3 && room.hasHabbosAt(to.x, to.y)) || (topItem != null && topItem.getBaseItem().getName().startsWith("fball_goal_") && currentStep != 1));
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java
index 73db3741..265b4cb9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java
@@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboItem;
+import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManager;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer;
import com.eu.habbo.messages.outgoing.users.UpdateUserLookComposer;
@@ -120,7 +121,7 @@ public class InteractionFootballGate extends HabboItem {
UserSavedLookEvent lookEvent = new UserSavedLookEvent(habbo, habbo.getHabboInfo().getGender(), oldlook);
Emulator.getPluginManager().fireEvent(lookEvent);
if (!lookEvent.isCancelled()) {
- habbo.getHabboInfo().setLook(lookEvent.newLook);
+ habbo.getHabboInfo().setLook(ClothingValidationManager.VALIDATE_ON_FBALLGATE ? ClothingValidationManager.validateLook(habbo, lookEvent.newLook, lookEvent.gender.name()) : lookEvent.newLook);
Emulator.getThreading().run(habbo.getHabboInfo());
habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo));
room.sendComposer(new RoomUserDataComposer(habbo).compose());
@@ -134,7 +135,7 @@ public class InteractionFootballGate extends HabboItem {
Emulator.getPluginManager().fireEvent(lookEvent);
if (!lookEvent.isCancelled()) {
habbo.getHabboStats().cache.put(CACHE_KEY, habbo.getHabboInfo().getLook());
- habbo.getHabboInfo().setLook(lookEvent.newLook);
+ habbo.getHabboInfo().setLook(ClothingValidationManager.VALIDATE_ON_FBALLGATE ? ClothingValidationManager.validateLook(habbo, lookEvent.newLook, lookEvent.gender.name()) : lookEvent.newLook);
Emulator.getThreading().run(habbo.getHabboInfo());
habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo));
room.sendComposer(new RoomUserDataComposer(habbo).compose());
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java
index 7386b365..a3ef5202 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java
@@ -26,7 +26,7 @@ public class InteractionFootballGoal extends InteractionGameTeamItem {
@Override
public boolean isWalkable() {
- return true;
+ return this.getBaseItem().allowWalk();
}
@Override
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java
new file mode 100644
index 00000000..3f1b06cb
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java
@@ -0,0 +1,8 @@
+package com.eu.habbo.habbohotel.items.interactions.interfaces;
+
+import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomUnit;
+
+public interface ConditionalGate {
+ public void onRejected(RoomUnit roomUnit, Room room, Object[] objects);
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
index 30ba25bd..d4b92964 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
index ba2b2bf7..ddce19a5 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java
@@ -4,6 +4,7 @@ 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.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionType;
@@ -14,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;
@@ -35,68 +38,65 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
- boolean foundSomething = false;
- for (HabboItem item : this.items) {
- boolean found = false;
+ if(this.items.isEmpty())
+ return true;
- THashSet stackedItems = room.getItemsAt(room.getLayout().getTile(item.getX(), item.getY()));
-
- if (stackedItems == null)
- continue;
-
- if (stackedItems.isEmpty() && this.all)
- return false;
-
- for (HabboItem i : stackedItems) {
- if (i == item)
- continue;
-
- if (i.getZ() >= item.getZ()) {
- found = true;
- foundSomething = true;
- }
- }
-
- if (this.all) {
- if (!found)
- return false;
- } else {
- if (found)
- return true;
- }
+ if(this.all) {
+ return this.items.stream().allMatch(item -> {
+ double minZ = item.getZ() + Item.getCurrentHeight(item);
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ });
+ }
+ else {
+ return this.items.stream().anyMatch(item -> {
+ double minZ = item.getZ() + Item.getCurrentHeight(item);
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ });
}
-
- return this.items.isEmpty() || foundSomething;
-
}
@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);
+ }
}
}
}
@@ -137,8 +137,6 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
int count;
packet.readInt();
@@ -147,6 +145,9 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
packet.readString();
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());
@@ -180,4 +181,14 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
this.items.remove(item);
}
}
+
+ static class JsonData {
+ boolean all;
+ List itemIds;
+
+ public JsonData(boolean all, List itemIds) {
+ this.all = all;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
index 304eded6..a0d07087 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java
@@ -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;
@@ -51,75 +51,58 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
if (this.items.isEmpty())
return true;
- THashMap> tiles = new THashMap<>();
- for (HabboItem item : this.items) {
- tiles.put(item, room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
- }
-
Collection habbos = room.getHabbos();
Collection bots = room.getCurrentBots().valueCollection();
Collection pets = room.getCurrentPets().valueCollection();
- for (Map.Entry> set : tiles.entrySet()) {
- boolean found = false;
- for (Habbo habbo : habbos) {
- if (set.getValue().contains(habbo.getRoomUnit().getCurrentLocation())) {
- found = true;
- }
- }
-
- if (!found) {
- for (Bot bot : bots) {
- if (set.getValue().contains(bot.getRoomUnit().getCurrentLocation())) {
- found = true;
- }
- }
- }
-
- if (!found) {
- for (Pet pet : pets) {
- if (set.getValue().contains(pet.getRoomUnit().getCurrentLocation())) {
- found = true;
- }
- }
- }
-
- if (!found) return false;
- }
-
- return true;
+ return this.items.stream().allMatch(item -> {
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
+ });
}
@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);
+ }
}
}
}
@@ -154,14 +137,15 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
int count;
packet.readInt();
packet.readString();
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());
@@ -196,4 +180,14 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
this.items.remove(item);
}
}
+
+ static class JsonData {
+ boolean all;
+ List itemIds;
+
+ public JsonData(boolean all, List itemIds) {
+ this.all = all;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
index 06e3cbaa..47c42d64 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java
@@ -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;
@@ -37,43 +39,55 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
+ if(items.isEmpty())
+ return false;
+
if (stuff != null) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
- HabboItem item = (HabboItem) stuff[0];
-
- for (HabboItem i : this.items) {
- if (i.getBaseItem().getId() == item.getBaseItem().getId())
- return true;
- }
-
- return false;
+ HabboItem triggeringItem = (HabboItem)stuff[0];
+ return this.items.stream().anyMatch(item -> item == triggeringItem);
}
}
}
- return true;
+
+ return false;
}
@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
@@ -104,12 +118,13 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
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());
@@ -139,4 +154,12 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
this.items.remove(item);
}
}
+
+ static class JsonData {
+ List itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
index b131e517..d5e93e21 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
index fdde8793..7e1580f0 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
index e47107c3..0d351e98 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
index d2ddf27c..b4f0df9f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
index 95e907ed..b40ee5e7 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
index 73371bab..76ece81c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java
@@ -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 settings;
@@ -49,7 +52,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
message.appendInt(this.settings.size());
for (WiredMatchFurniSetting item : this.settings)
- message.appendInt(item.itemId);
+ message.appendInt(item.item_id);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
@@ -67,8 +70,6 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
@Override
public boolean saveData(ClientMessage packet) {
- this.settings.clear();
-
int count;
packet.readInt();
@@ -84,6 +85,9 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
return true;
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();
@@ -104,7 +108,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
THashSet s = new THashSet<>();
for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
+ HabboItem item = room.getHabboItem(setting.item_id);
if (item != null) {
if (this.state) {
@@ -137,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
@@ -186,7 +194,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
THashSet remove = new THashSet<>();
for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
+ HabboItem item = room.getHabboItem(setting.item_id);
if (item == null) {
remove.add(setting);
}
@@ -197,4 +205,38 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition
}
}
}
+
+ @Override
+ public THashSet 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 settings;
+
+ public JsonData(boolean state, boolean position, boolean direction, List settings) {
+ this.state = state;
+ this.position = position;
+ this.direction = direction;
+ this.settings = settings;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
index a1fa3c5c..0be6ba15 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
index c64fb8b5..279f61bd 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java
@@ -4,6 +4,7 @@ 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.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
@@ -15,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;
@@ -39,50 +42,62 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
if (this.items.isEmpty())
return true;
- for (HabboItem item : this.items) {
- THashSet things = room.getItemsAt(item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item));
- things.removeAll(this.items);
- if (!things.isEmpty()) {
- if (this.all)
- return false;
- else
- continue;
- }
- return true;
+ if(this.all) {
+ return this.items.stream().allMatch(item -> {
+ double minZ = item.getZ() + Item.getCurrentHeight(item);
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ });
+ }
+ else {
+ return this.items.stream().anyMatch(item -> {
+ double minZ = item.getZ() + Item.getCurrentHeight(item);
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ));
+ });
}
-
- return false;
}
@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);
+ }
}
}
}
@@ -123,16 +138,16 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
- int count;
packet.readInt();
this.all = packet.readInt() == 1;
packet.readString();
- count = packet.readInt();
+ 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());
@@ -169,6 +184,18 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition {
@Override
public WiredConditionOperator operator() {
- return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR;
+ // NICE TRY BUT THAT'S NOT HOW IT WORKS. NOTHING IN HABBO IS AN "OR" CONDITION - EVERY CONDITION MUST BE SUCCESS FOR THE STACK TO EXECUTE, BUT LET'S LEAVE IT IMPLEMENTED FOR PLUGINS TO USE.
+ //return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR;
+ return WiredConditionOperator.AND;
+ }
+
+ static class JsonData {
+ boolean all;
+ List itemIds;
+
+ public JsonData(boolean all, List itemIds) {
+ this.all = all;
+ this.itemIds = itemIds;
+ }
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
index ef61c69c..87f3bc9a 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java
@@ -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;
@@ -51,75 +51,58 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
if (this.items.isEmpty())
return true;
- THashMap> tiles = new THashMap<>();
- for (HabboItem item : this.items) {
- tiles.put(item, room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
- }
-
Collection habbos = room.getHabbos();
Collection bots = room.getCurrentBots().valueCollection();
Collection pets = room.getCurrentPets().valueCollection();
- for (Map.Entry> set : tiles.entrySet()) {
- if (!habbos.isEmpty()) {
- for (Habbo habbo : habbos) {
- if (set.getValue().contains(habbo.getRoomUnit().getCurrentLocation())) {
- return false;
- }
- }
- }
-
- if (!bots.isEmpty()) {
- for (Bot bot : bots) {
- if (set.getValue().contains(bot.getRoomUnit().getCurrentLocation())) {
- return false;
- }
- }
- }
-
- if (!pets.isEmpty()) {
- for (Pet pet : pets) {
- if (set.getValue().contains(pet.getRoomUnit().getCurrentLocation())) {
- return false;
- }
- }
- }
-
- }
-
- return true;
+ return this.items.stream().noneMatch(item -> {
+ THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) ||
+ pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation()));
+ });
}
@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);
+ }
}
}
}
@@ -154,14 +137,14 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
- int count;
packet.readInt();
packet.readString();
- count = packet.readInt();
+ 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());
@@ -196,4 +179,14 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.items.remove(item);
}
}
+
+ static class JsonData {
+ boolean all;
+ List itemIds;
+
+ public JsonData(boolean all, List itemIds) {
+ this.all = all;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
index 95b5d8e3..30c9ea51 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java
@@ -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;
@@ -32,15 +34,14 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
this.refresh();
+ if(items.isEmpty())
+ return true;
+
if (stuff != null) {
if (stuff.length >= 1) {
if (stuff[0] instanceof HabboItem) {
- HabboItem item = (HabboItem) stuff[0];
-
- for (HabboItem i : this.items) {
- if (i.getBaseItem().getId() == item.getBaseItem().getId())
- return false;
- }
+ HabboItem triggeringItem = (HabboItem)stuff[0];
+ return this.items.stream().noneMatch(item -> item == triggeringItem);
}
}
}
@@ -51,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
@@ -103,12 +118,13 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
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());
@@ -138,4 +154,12 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
this.items.remove(item);
}
}
+
+ static class JsonData {
+ List itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
index 194d47c1..3075c4ff 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
index 0994a2a3..ae1c20bb 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
index 3a30238f..6df96d6b 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
index fba63af0..b805c7b1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java
@@ -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;
@@ -31,27 +32,31 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
- if (habbo.getHabboInfo().getGamePlayer() != null) {
- return !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor);
- }
- return true; // user is not part of any team
+ return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team
}
- return false;
+ return true;
}
@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;
}
@@ -91,4 +96,12 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition {
return true;
}
+
+ static class JsonData {
+ GameTeamColors teamColor;
+
+ public JsonData(GameTeamColors teamColor) {
+ this.teamColor = teamColor;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
index 2f0dc9d4..bc29186d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java
@@ -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 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 s = new THashSet<>();
-
- for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
-
- 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 false;
- } else {
- s.add(setting);
- }
- }
-
- if (!s.isEmpty()) {
- for (WiredMatchFurniSetting setting : s) {
- this.settings.remove(setting);
- }
- }
-
- return true;
- }
-
- @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.itemId);
-
- 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) {
- this.settings.clear();
-
- int count;
- 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;
-
- count = packet.readInt();
-
- 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 remove = new THashSet<>();
-
- for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
- if (item == null) {
- remove.add(setting);
- }
- }
-
- for (WiredMatchFurniSetting setting : remove) {
- this.settings.remove(setting);
- }
- }
- }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
index eb853f9c..21ea027e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java
@@ -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 items = new THashSet<>();
-
public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@@ -31,115 +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;
- for (HabboItem item : this.items) {
- if (RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()).contains(roomUnit.getX(), roomUnit.getY()))
- return false;
- }
-
- return true;
- }
-
- @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) {
- this.items.clear();
-
- packet.readInt();
- packet.readString();
-
- int count = packet.readInt();
-
- 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 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);
- }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
index 9349cbb2..027db810 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
index 5cb27d1c..250d4751 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java
@@ -4,7 +4,7 @@ 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.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.wired.WiredConditionOperator;
@@ -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 items = new THashSet<>();
+ protected THashSet items = new THashSet<>();
public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -32,45 +34,74 @@ public class WiredConditionTriggerOnFurni 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;
+ return false;
- for (HabboItem item : this.items) {
- if (RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()).contains(roomUnit.getX(), roomUnit.getY()))
- return true;
+ 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
+ * */
+ if (!roomUnit.isWalking()) {
+ THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation());
+ return this.items.stream().anyMatch(itemsAtUser::contains);
+ } else {
+ RoomTile firstTileInPath = room.getLayout()
+ .findPath(roomUnit.getCurrentLocation(), roomUnit.getGoal(), roomUnit.getGoal(), roomUnit)
+ .peek();
+
+ if (firstTileInPath == null)
+ return false;
+
+ return this.items
+ .stream()
+ .anyMatch(conditionItem -> conditionItem
+ .getOccupyingTiles(room.getLayout())
+ .contains(firstTileInPath)
+ );
}
-
- return false;
}
@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.valueOf(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);
+ }
}
}
}
@@ -108,12 +139,13 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override
public boolean saveData(ClientMessage packet) {
- this.items.clear();
-
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());
@@ -130,7 +162,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
return true;
}
- private void refresh() {
+ protected void refresh() {
THashSet items = new THashSet<>();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
@@ -148,6 +180,14 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
@Override
public WiredConditionOperator operator() {
- return WiredConditionOperator.OR;
+ return WiredConditionOperator.AND;
+ }
+
+ static class JsonData {
+ List itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
}
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
index ec22bf63..f0a5b3f8 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java
@@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
+import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
@@ -7,12 +8,16 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
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.messages.incoming.wired.WiredSaveException;
+import com.google.gson.Gson;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
+import java.util.regex.Pattern;
public class WiredEffectBotClothes extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_CLOTHES;
@@ -44,18 +49,27 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
-
- String[] data = packet.readString().split(((char) 9) + "");
-
- if (data.length == 2) {
- this.botName = data[0];
- this.botLook = data[1];
- }
-
+ String dataString = packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ String splitBy = "\t";
+ if(!dataString.contains(splitBy))
+ throw new WiredSaveException("Malformed data string");
+
+ String[] data = dataString.split(Pattern.quote(splitBy));
+
+ if (data.length != 2)
+ throw new WiredSaveException("Malformed data string. Invalid data length");
+
+ this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.botLook = data[1];
+ this.setDelay(delay);
return true;
}
@@ -69,31 +83,39 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List bots = room.getBots(this.botName);
- if (bots.size() != 1) {
- return false;
+ if (bots.size() == 1) {
+ Bot bot = bots.get(0);
+ bot.setFigure(this.botLook);
}
- Bot bot = bots.get(0);
- bot.setFigure(this.botLook);
-
return true;
}
@Override
public String getWiredData() {
- return this.getDelay() + "" + ((char) 9) + "" +
- this.botName + ((char) 9) +
- this.botLook;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split(((char) 9) + "");
+ String wiredData = set.getString("wired_data");
- if (data.length >= 3) {
- this.setDelay(Integer.valueOf(data[0]));
- this.botName = data[1];
- this.botLook = data[2];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.botName = data.bot_name;
+ this.botLook = data.look;
+ }
+ else {
+ String[] data = wiredData.split(((char) 9) + "");
+
+ if (data.length >= 3) {
+ this.setDelay(Integer.valueOf(data[0]));
+ this.botName = data[1];
+ this.botLook = data[2];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -119,4 +141,16 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
public void setBotLook(String botLook) {
this.botLook = botLook;
}
+
+ static class JsonData {
+ String bot_name;
+ String look;
+ int delay;
+
+ public JsonData(String bot_name, String look, int delay) {
+ this.bot_name = bot_name;
+ this.look = look;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
index 928068af..ee1b28b1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java
@@ -1,5 +1,6 @@
package com.eu.habbo.habbohotel.items.interactions.wired.effects;
+import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
@@ -9,8 +10,10 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -67,13 +70,25 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
+ int mode = packet.readInt();
- this.mode = packet.readInt();
- this.botName = packet.readString().replace("\t", "");
+ if(mode != 0 && mode != 1)
+ throw new WiredSaveException("Mode is invalid");
+
+ String botName = packet.readString().replace("\t", "");
+ botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.botName = botName;
+ this.mode = mode;
+ this.setDelay(delay);
+
return true;
}
@@ -105,17 +120,29 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + this.botName;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split(((char) 9) + "");
+ String wiredData = set.getString("wired_data");
- if (data.length == 3) {
- this.setDelay(Integer.valueOf(data[0]));
- this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0);
- this.botName = data[2];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.mode = data.mode;
+ this.botName = data.bot_name;
+ }
+ else {
+ String[] data = wiredData.split(((char) 9) + "");
+
+ if (data.length == 3) {
+ this.setDelay(Integer.valueOf(data[0]));
+ this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0);
+ this.botName = data[2];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -130,4 +157,16 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ String bot_name;
+ int mode;
+ int delay;
+
+ public JsonData(String bot_name, int mode, int delay) {
+ this.bot_name = bot_name;
+ this.mode = mode;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
index 94173cdd..27fc7888 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java
@@ -7,13 +7,17 @@ import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
import com.eu.habbo.habbohotel.rooms.Room;
+import com.eu.habbo.habbohotel.rooms.RoomTile;
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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem;
-import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit;
+import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -70,13 +74,25 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.itemId = packet.readInt();
- this.botName = packet.readString();
+ int itemId = packet.readInt();
+
+ if(itemId < 0)
+ itemId = 0;
+
+ String botName = packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.itemId = itemId;
+ this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.setDelay(delay);
+
return true;
}
@@ -94,15 +110,22 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
Bot bot = bots.get(0);
List tasks = new ArrayList<>();
- tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId));
+ tasks.add(new RoomUnitGiveHanditem(roomUnit, room, this.itemId));
tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0));
+ tasks.add(() -> {
+ if(roomUnit.getRoom() != null && roomUnit.getRoom().getId() == room.getId() && roomUnit.getCurrentLocation().distance(bot.getRoomUnit().getCurrentLocation()) < 2) {
+ WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{});
+ }
+ });
+
+ RoomTile tile = bot.getRoomUnit().getClosestAdjacentTile(roomUnit.getX(), roomUnit.getY(), true);
+
+ if(tile != null) {
+ bot.getRoomUnit().setGoalLocation(tile);
+ }
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
-
- List failedReach = new ArrayList<>();
- failedReach.add(() -> tasks.forEach(Runnable::run));
-
- Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach));
+ Emulator.getThreading().run(new RoomUnitWalkToLocation(bot.getRoomUnit(), tile, room, tasks, tasks));
return true;
}
@@ -112,17 +135,29 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "" + ((char) 9) + "" + this.itemId + "" + ((char) 9) + "" + this.botName;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.itemId, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split(((char) 9) + "");
+ String wiredData = set.getString("wired_data");
- if (data.length == 3) {
- this.setDelay(Integer.valueOf(data[0]));
- this.itemId = Integer.valueOf(data[1]);
- this.botName = data[2];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.itemId = data.item_id;
+ this.botName = data.bot_name;
+ }
+ else {
+ String[] data = wiredData.split(((char) 9) + "");
+
+ if (data.length == 3) {
+ this.setDelay(Integer.valueOf(data[0]));
+ this.itemId = Integer.valueOf(data[1]);
+ this.botName = data[2];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -137,4 +172,16 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ String bot_name;
+ int item_id;
+ int delay;
+
+ public JsonData(String bot_name, int item_id, int delay) {
+ this.bot_name = bot_name;
+ this.item_id = item_id;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
index e73978a0..735b0f39 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java
@@ -9,12 +9,16 @@ 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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
+import java.util.regex.Pattern;
public class WiredEffectBotTalk extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TALK;
@@ -48,20 +52,35 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.mode = packet.readInt();
+ int mode = packet.readInt();
- String[] data = packet.readString().split(((char) 9) + "");
+ if(mode != 0 && mode != 1)
+ throw new WiredSaveException("Mode is invalid");
- if (data.length == 2) {
- this.botName = data[0];
- this.message = data[1];
- }
+ String dataString = packet.readString();
+
+ String splitBy = "\t";
+ if(!dataString.contains(splitBy))
+ throw new WiredSaveException("Malformed data string");
+
+ String[] data = dataString.split(Pattern.quote(splitBy));
+
+ if (data.length != 2)
+ throw new WiredSaveException("Malformed data string. Invalid data length");
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.setDelay(delay);
+ this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.mode = mode;
return true;
}
@@ -78,24 +97,29 @@ 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 bots = room.getBots(this.botName);
- if (bots.size() != 1) {
- return false;
- }
+ if (bots.size() == 1) {
+ Bot bot = bots.get(0);
- Bot bot = bots.get(0);
-
- if (this.mode == 1) {
- bot.shout(message);
- } else {
- bot.talk(message);
+ if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) {
+ if (this.mode == 1) {
+ bot.shout(message);
+ } else {
+ bot.talk(message);
+ }
+ }
}
return true;
@@ -103,19 +127,31 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + "" + this.botName + "" + ((char) 9) + "" + this.message;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String d = set.getString("wired_data");
- String[] data = d.split(((char) 9) + "");
+ String wiredData = set.getString("wired_data");
- if (data.length == 4) {
- this.setDelay(Integer.valueOf(data[0]));
- this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
- this.botName = data[2];
- this.message = data[3];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.mode = data.mode;
+ this.botName = data.bot_name;
+ this.message = data.message;
+ }
+ else {
+ String[] data = wiredData.split(((char) 9) + "");
+
+ if (data.length == 4) {
+ this.setDelay(Integer.valueOf(data[0]));
+ this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
+ this.botName = data[2];
+ this.message = data[3];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -155,4 +191,18 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
protected long requiredCooldown() {
return 500;
}
+
+ static class JsonData {
+ String bot_name;
+ int mode;
+ String message;
+ int delay;
+
+ public JsonData(String bot_name, int mode, String message, int delay) {
+ this.bot_name = bot_name;
+ this.mode = mode;
+ this.message = message;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
index aec24c88..8fede69c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java
@@ -10,14 +10,18 @@ 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.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Pattern;
public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TALK_TO_AVATAR;
@@ -69,19 +73,34 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.mode = packet.readInt();
- String[] data = packet.readString().split("" + ((char) 9));
+ int mode = packet.readInt();
- if (data.length == 2) {
- this.botName = data[0];
- this.message = data[1];
- }
+ if(mode != 0 && mode != 1)
+ throw new WiredSaveException("Mode is invalid");
+
+ String dataString = packet.readString();
+ String splitBy = "\t";
+ if(!dataString.contains(splitBy))
+ throw new WiredSaveException("Malformed data string");
+
+ String[] data = dataString.split(Pattern.quote(splitBy));
+
+ if (data.length != 2)
+ throw new WiredSaveException("Malformed data string. Invalid data length");
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.mode = mode;
+ this.setDelay(delay);
return true;
}
@@ -97,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 bots = room.getBots(this.botName);
@@ -110,10 +134,12 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
Bot bot = bots.get(0);
- if (this.mode == 1) {
- bot.whisper(m, habbo);
- } else {
- bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
+ if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ m })) {
+ if (this.mode == 1) {
+ bot.whisper(m, habbo);
+ } else {
+ bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
+ }
}
return true;
@@ -124,18 +150,31 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + "" + this.botName + "" + ((char) 9) + "" + this.message;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split(((char) 9) + "");
+ String wiredData = set.getString("wired_data");
- if (data.length == 4) {
- this.setDelay(Integer.valueOf(data[0]));
- this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
- this.botName = data[2];
- this.message = data[3];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.mode = data.mode;
+ this.botName = data.bot_name;
+ this.message = data.message;
+ }
+ else {
+ String[] data = wiredData.split(((char) 9) + "");
+
+ if (data.length == 4) {
+ this.setDelay(Integer.valueOf(data[0]));
+ this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0;
+ this.botName = data[2];
+ this.message = data[3];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -151,4 +190,18 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ String bot_name;
+ int mode;
+ String message;
+ int delay;
+
+ public JsonData(String bot_name, int mode, String message, int delay) {
+ this.bot_name = bot_name;
+ this.mode = mode;
+ this.message = message;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
index b88e7877..07bbac6f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java
@@ -14,6 +14,7 @@ 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.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
import com.eu.habbo.threading.runnables.RoomUnitTeleport;
import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer;
@@ -21,8 +22,10 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
public class WiredEffectBotTeleport extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_TELEPORT;
@@ -77,6 +80,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
}
+ Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
}
@@ -110,19 +114,36 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.botName = packet.readString();
+ String botName = packet.readString();
+ int itemsCount = packet.readInt();
- this.items.clear();
-
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.setDelay(delay);
return true;
}
@@ -164,38 +185,57 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
@Override
public String getWiredData() {
- StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t" + this.botName + ";");
+ ArrayList itemIds = new ArrayList<>();
- if (this.items != null && !this.items.isEmpty()) {
+ if (this.items != null) {
for (HabboItem item : this.items) {
if (item.getRoomId() != 0) {
- wiredData.append(item.getId()).append(";");
+ itemIds.add(item.getId());
}
}
}
- return wiredData.toString();
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>();
- String[] wiredData = set.getString("wired_data").split("\t");
- if (wiredData.length >= 2) {
- this.setDelay(Integer.valueOf(wiredData[0]));
- String[] data = wiredData[1].split(";");
+ String wiredData = set.getString("wired_data");
- if (data.length > 1) {
- this.botName = data[0];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.botName = data.bot_name;
- for (int i = 1; i < data.length; i++) {
- HabboItem item = room.getHabboItem(Integer.valueOf(data[i]));
+ for(int itemId : data.items) {
+ HabboItem item = room.getHabboItem(itemId);
- if (item != null)
- this.items.add(item);
+ if (item != null)
+ this.items.add(item);
+ }
+ }
+ else {
+ String[] wiredDataSplit = set.getString("wired_data").split("\t");
+
+ if (wiredDataSplit.length >= 2) {
+ this.setDelay(Integer.valueOf(wiredDataSplit[0]));
+ String[] data = wiredDataSplit[1].split(";");
+
+ if (data.length > 1) {
+ this.botName = data[0];
+
+ for (int i = 1; i < data.length; i++) {
+ HabboItem item = room.getHabboItem(Integer.valueOf(data[i]));
+
+ if (item != null)
+ this.items.add(item);
+ }
}
}
+
+ this.needsUpdate(true);
}
}
@@ -205,4 +245,16 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
this.items.clear();
this.setDelay(0);
}
+
+ static class JsonData {
+ String bot_name;
+ List items;
+ int delay;
+
+ public JsonData(String bot_name, List items, int delay) {
+ this.bot_name = bot_name;
+ this.items = items;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
index 1b0efe08..73906c87 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java
@@ -12,26 +12,29 @@ 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.incoming.wired.WiredSaveException;
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 WiredEffectBotWalkToFurni extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.BOT_MOVE;
- private THashSet items;
+ private List items;
private String botName = "";
public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
- this.items = new THashSet<>();
+ this.items = new ArrayList<>();
}
public WiredEffectBotWalkToFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
- this.items = new THashSet<>();
+ this.items = new ArrayList<>();
}
@Override
@@ -64,19 +67,36 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.botName = packet.readString();
+ String botName = packet.readString();
+ int itemsCount = packet.readInt();
- this.items.clear();
-
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.setDelay(delay);
return true;
}
@@ -91,33 +111,23 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
List bots = room.getBots(this.botName);
if (this.items.isEmpty() || bots.size() != 1) {
- return false;
+ return true;
}
Bot bot = bots.get(0);
- THashSet items = new THashSet<>();
+ this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
- for (HabboItem item : this.items) {
- if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
- items.add(item);
- }
+ // Bots shouldn't walk to the tile they are already standing on
+ List possibleItems = this.items.stream()
+ .filter(item -> !room.getBotsOnItem(item).contains(bot))
+ .collect(Collectors.toList());
- for (HabboItem item : items) {
- this.items.remove(item);
- }
+ // Get a random tile of possible tiles to walk to
+ if (possibleItems.size() > 0) {
+ HabboItem item = possibleItems.get(Emulator.getRandom().nextInt(possibleItems.size()));
- if (this.items.size() > 0) {
- int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
- int j = 1;
- for (HabboItem item : this.items) {
- if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
- if (i == j) {
- bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
- break;
- } else {
- j++;
- }
- }
+ if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
+ bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
}
}
@@ -126,38 +136,57 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
@Override
public String getWiredData() {
- StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t" + this.botName + ";");
+ ArrayList itemIds = new ArrayList<>();
- if (this.items != null && !this.items.isEmpty()) {
+ if (this.items != null) {
for (HabboItem item : this.items) {
if (item.getRoomId() != 0) {
- wiredData.append(item.getId()).append(";");
+ itemIds.add(item.getId());
}
}
}
- return wiredData.toString();
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- this.items = new THashSet<>();
- String[] wiredData = set.getString("wired_data").split("\t");
+ this.items = new ArrayList<>();
- if (wiredData.length > 1) {
- this.setDelay(Integer.valueOf(wiredData[0]));
- String[] data = wiredData[1].split(";");
+ String wiredData = set.getString("wired_data");
- if (data.length >= 1) {
- this.botName = data[0];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.botName = data.bot_name;
- for (int i = 1; i < data.length; i++) {
- HabboItem item = room.getHabboItem(Integer.valueOf(data[i]));
+ for(int itemId : data.items) {
+ HabboItem item = room.getHabboItem(itemId);
- if (item != null)
- this.items.add(item);
+ if (item != null)
+ this.items.add(item);
+ }
+ }
+ else {
+ String[] wiredDataSplit = set.getString("wired_data").split("\t");
+
+ if (wiredDataSplit.length >= 2) {
+ this.setDelay(Integer.valueOf(wiredDataSplit[0]));
+ String[] data = wiredDataSplit[1].split(";");
+
+ if (data.length > 1) {
+ this.botName = data[0];
+
+ for (int i = 1; i < data.length; i++) {
+ HabboItem item = room.getHabboItem(Integer.valueOf(data[i]));
+
+ if (item != null)
+ this.items.add(item);
+ }
}
}
+
+ this.needsUpdate(true);
}
}
@@ -167,4 +196,16 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
this.botName = "";
this.setDelay(0);
}
+
+ static class JsonData {
+ String bot_name;
+ List items;
+ int delay;
+
+ public JsonData(String bot_name, List items, int delay) {
+ this.bot_name = bot_name;
+ this.items = items;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
index bbb44819..0ce892d7 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java
@@ -5,19 +5,19 @@ import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.rooms.*;
-import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
-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.habbohotel.wired.*;
import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.map.hash.THashMap;
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.Map;
public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@@ -31,9 +31,9 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.MOVE_DIRECTION;
- private final THashMap items = new THashMap<>(0);
+ private final THashMap items = new THashMap<>(0);
private RoomUserRotation startRotation = RoomUserRotation.NORTH;
- private int rotateAction = 0;
+ private int blockedAction = 0;
public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
@@ -57,29 +57,56 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
}
if (this.items.isEmpty()) return false;
- for (Map.Entry entry : this.items.entrySet()) {
- RoomUserRotation currentRotation = entry.getValue();
- RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue());
+
+ for (Map.Entry entry : this.items.entrySet()) {
+ HabboItem item = entry.getKey();
+ RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
int count = 1;
- while ((targetTile == null || !targetTile.getAllowStack() || targetTile.state == RoomTileState.INVALID || targetTile.state == RoomTileState.BLOCKED) && count < 8) {
- entry.setValue(this.nextRotation(entry.getValue()));
- targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue());
- count++;
- }
+ while ((targetTile == null || targetTile.state == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) {
+ entry.getValue().direction = this.nextRotation(entry.getValue().direction);
- if (targetTile != null && targetTile.state == RoomTileState.OPEN) {
- boolean hasHabbos = false;
- for (Habbo habbo : room.getHabbosAt(targetTile)) {
- hasHabbos = true;
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{entry.getKey()}));
+ RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().direction.getValue());
+ if (tile != null && tile.state != RoomTileState.INVALID) {
+ targetTile = tile;
}
- if (!hasHabbos) {
- THashSet refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
- room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, targetTile, targetTile.getStackHeight() - entry.getKey().getZ(), room).compose());
- room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
- room.updateTiles(refreshTiles);
+ count++;
+ }
+ }
+
+ for (Map.Entry entry : this.items.entrySet()) {
+ HabboItem item = entry.getKey();
+ int newDirection = entry.getValue().direction.getValue();
+
+ RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirection);
+
+ if(item.getRotation() != entry.getValue().rotation) {
+ if(room.furnitureFitsAt(targetTile, item, entry.getValue().rotation, false) != FurnitureMovementError.NONE)
+ continue;
+
+ room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().rotation, null, true);
+ }
+
+ boolean hasRoomUnits = false;
+ THashSet newOccupiedTiles = room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
+ for(RoomTile tile : newOccupiedTiles) {
+ for (RoomUnit _roomUnit : room.getRoomUnits(tile)) {
+ hasRoomUnits = true;
+ if(_roomUnit.getCurrentLocation() == targetTile) {
+ Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
+ break;
+ }
+ }
+ }
+
+ if (targetTile != null && targetTile.state != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) {
+ if (!hasRoomUnits) {
+ RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY());
+ double oldZ = entry.getKey().getZ();
+ if(room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
+ room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, oldLocation, oldZ, targetTile, entry.getKey().getZ(), 0, room).compose());
+ }
}
}
}
@@ -89,41 +116,63 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
@Override
public String getWiredData() {
- StringBuilder data = new StringBuilder(this.getDelay() + this.startRotation.getValue() + "\t" + this.rotateAction + "\t" + this.items.size());
-
- for (Map.Entry entry : this.items.entrySet()) {
- data.append("\t").append(entry.getKey().getId()).append(":").append(entry.getValue().getValue());
- }
-
- return data.toString();
+ ArrayList settings = new ArrayList<>(this.items.values());
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split("\t");
- if (data.length >= 1) {
- this.setDelay(Integer.valueOf(data[0]));
+ this.items.clear();
+
+ String wiredData = set.getString("wired_data");
+
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.startRotation = data.start_direction;
+ this.blockedAction = data.blocked_action;
+
+ for(WiredChangeDirectionSetting setting : data.items) {
+ HabboItem item = room.getHabboItem(setting.item_id);
+
+ if (item != null) {
+ this.items.put(item, setting);
+ }
+ }
}
- if (data.length >= 3) {
- this.startRotation = RoomUserRotation.fromValue(Integer.valueOf(data[0]));
- this.rotateAction = Integer.valueOf(data[1]);
+ else {
+ String[] data = wiredData.split("\t");
- int itemCount = Integer.valueOf(data[2]);
+ if (data.length >= 4) {
+ this.setDelay(Integer.parseInt(data[0]));
+ this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1]));
+ this.blockedAction = Integer.parseInt(data[2]);
- if (itemCount > 0) {
- for (int i = 3; i < data.length; i++) {
- String[] subData = data[i].split(":");
+ int itemCount = Integer.parseInt(data[3]);
- if (subData.length == 2) {
- HabboItem item = room.getHabboItem(Integer.valueOf(subData[0]));
+ if (itemCount > 0) {
+ for (int i = 4; i < data.length; i++) {
+ String[] subData = data[i].split(":");
- if (item != null) {
- this.items.put(item, RoomUserRotation.fromValue(Integer.valueOf(subData[1])));
+ if (subData.length >= 2) {
+ HabboItem item = room.getHabboItem(Integer.parseInt(subData[0]));
+
+ if (item != null) {
+ int rotation = item.getRotation();
+
+ if (subData.length > 2) {
+ rotation = Integer.parseInt(subData[2]);
+ }
+
+ this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1]))));
+ }
}
}
}
}
+
+ this.needsUpdate(true);
}
}
@@ -131,7 +180,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public void onPickUp() {
this.setDelay(0);
this.items.clear();
- this.rotateAction = 0;
+ this.blockedAction = 0;
this.startRotation = RoomUserRotation.NORTH;
}
@@ -145,15 +194,15 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
message.appendBoolean(false);
message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION);
message.appendInt(this.items.size());
- for (Map.Entry item : this.items.entrySet()) {
+ for (Map.Entry item : this.items.entrySet()) {
message.appendInt(item.getKey().getId());
}
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
message.appendString("");
message.appendInt(2);
- message.appendInt(this.startRotation.getValue());
- message.appendInt(this.rotateAction);
+ message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0);
+ message.appendInt(this.blockedAction);
message.appendInt(0);
message.appendInt(this.getType().code);
message.appendInt(this.getDelay());
@@ -161,30 +210,60 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
- this.items.clear();
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.startRotation = RoomUserRotation.fromValue(packet.readInt());
- this.rotateAction = packet.readInt();
+ int startDirectionInt = packet.readInt();
+
+ if(startDirectionInt < 0 || startDirectionInt > 7 || (startDirectionInt % 2) != 0) {
+ throw new WiredSaveException("Start direction is invalid");
+ }
+
+ RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt);
+
+ int blockedActionInt = packet.readInt();
+
+ if(blockedActionInt < 0 || blockedActionInt > 6) {
+ throw new WiredSaveException("Blocked action is invalid");
+ }
+
packet.readString();
- int furniCount = packet.readInt();
- for (int i = 0; i < furniCount; i++) {
- HabboItem item = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(packet.readInt());
+ int itemsCount = packet.readInt();
- if (item != null) {
- this.items.put(item, this.startRotation);
- }
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+
+ THashMap newItems = new THashMap<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.put(it, new WiredChangeDirectionSetting(it.getId(), it.getRotation(), startDirection));
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.putAll(newItems);
+ this.startRotation = startDirection;
+ this.blockedAction = blockedActionInt;
+ this.setDelay(delay);
+
return true;
}
private RoomUserRotation nextRotation(RoomUserRotation currentRotation) {
- switch (this.rotateAction) {
+ switch (this.blockedAction) {
case ACTION_TURN_BACK:
- return RoomUserRotation.fromValue(currentRotation.getValue() + 4);
-
+ return RoomUserRotation.fromValue(currentRotation.getValue()).getOpposite();
case ACTION_TURN_LEFT_45:
return RoomUserRotation.counterClockwise(currentRotation);
case ACTION_TURN_LEFT_90:
@@ -198,8 +277,6 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
case ACTION_WAIT:
default:
return currentRotation;
-
-
}
}
@@ -207,4 +284,18 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
+
+ static class JsonData {
+ RoomUserRotation start_direction;
+ int blocked_action;
+ List items;
+ int delay;
+
+ public JsonData(RoomUserRotation start_direction, int blocked_action, List items, int delay) {
+ this.start_direction = start_direction;
+ this.blocked_action = blocked_action;
+ this.items = items;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
index 1a84a14d..63920ffc 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
index 5bca3009..0bd62164 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java
@@ -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 gnu.trove.procedure.TObjectProcedure;
@@ -101,21 +102,31 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "\t" + this.amount;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String wireData = set.getString("wired_data");
- this.amount = 0;
+ String wiredData = set.getString("wired_data");
- 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.amount = data.amount;
+ this.setDelay(data.delay);
+ }
+ else {
+ this.amount = 0;
- try {
- this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]);
- } catch (Exception e) {
+ if (wiredData.split("\t").length >= 2) {
+ super.setDelay(Integer.valueOf(wiredData.split("\t")[0]));
+
+ try {
+ this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]);
+ } catch (Exception e) {
+ }
}
+
+ this.needsUpdate(true);
}
}
@@ -129,4 +140,14 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ int amount;
+ int delay;
+
+ public JsonData(int amount, int delay) {
+ this.amount = amount;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
index 233a97e9..4a3b966f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java
@@ -10,6 +10,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 gnu.trove.procedure.TObjectProcedure;
@@ -101,22 +102,32 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "\t" + this.respects;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.respects, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String wireData = set.getString("wired_data");
- String[] data = wireData.split("\t");
- this.respects = 0;
+ String wiredData = set.getString("wired_data");
- if (data.length >= 2) {
- super.setDelay(Integer.valueOf(data[0]));
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.respects = data.amount;
+ this.setDelay(data.delay);
+ }
+ else {
+ String[] data = wiredData.split("\t");
+ this.respects = 0;
- try {
- this.respects = Integer.valueOf(data[1]);
- } catch (Exception e) {
+ if (data.length >= 2) {
+ super.setDelay(Integer.valueOf(data[0]));
+
+ try {
+ this.respects = Integer.valueOf(data[1]);
+ } catch (Exception e) {
+ }
}
+
+ this.needsUpdate(true);
}
}
@@ -130,4 +141,14 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ int amount;
+ int delay;
+
+ public JsonData(int amount, int delay) {
+ this.amount = amount;
+ this.delay = delay;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
index e61973e9..f4c3a2ba 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java
@@ -56,43 +56,52 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override
public String getWiredData() {
- StringBuilder data = new StringBuilder(this.limit + ":" + this.given + ":" + this.rewardTime + ":" + (this.uniqueRewards ? 1 : 0) + ":" + this.limitationInterval + ":" + this.getDelay() + ":");
- if (this.rewardItems.isEmpty()) {
- data.append("\t");
- } else {
- for (WiredGiveRewardItem item : this.rewardItems) {
- data.append(item.toString()).append(";");
- }
- }
-
- return data.toString();
+ ArrayList rewards = new ArrayList<>(this.rewardItems);
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String[] data = set.getString("wired_data").split(":");
- if (data.length > 0) {
- this.limit = Integer.valueOf(data[0]);
- this.given = Integer.valueOf(data[1]);
- this.rewardTime = Integer.valueOf(data[2]);
- this.uniqueRewards = data[3].equals("1");
- this.limitationInterval = Integer.valueOf(data[4]);
- this.setDelay(Integer.valueOf(data[5]));
+ String wiredData = set.getString("wired_data");
- if (data.length > 6) {
- if (!data[6].equalsIgnoreCase("\t")) {
- String[] items = data[6].split(";");
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.limit = data.limit;
+ this.given = data.given;
+ this.rewardTime = data.reward_time;
+ this.uniqueRewards = data.unique_rewards;
+ this.limitationInterval = data.limit_interval;
+ this.rewardItems.clear();
+ this.rewardItems.addAll(data.rewards);
+ }
+ else {
+ String[] data = wiredData.split(":");
+ if (data.length > 0) {
+ this.limit = Integer.valueOf(data[0]);
+ this.given = Integer.valueOf(data[1]);
+ this.rewardTime = Integer.valueOf(data[2]);
+ this.uniqueRewards = data[3].equals("1");
+ this.limitationInterval = Integer.valueOf(data[4]);
+ this.setDelay(Integer.valueOf(data[5]));
- this.rewardItems.clear();
+ if (data.length > 6) {
+ if (!data[6].equalsIgnoreCase("\t")) {
+ String[] items = data[6].split(";");
- for (String s : items) {
- try {
- this.rewardItems.add(new WiredGiveRewardItem(s));
- } catch (Exception e) {
+ this.rewardItems.clear();
+
+ for (String s : items) {
+ try {
+ this.rewardItems.add(new WiredGiveRewardItem(s));
+ } catch (Exception e) {
+ }
}
}
}
+
+ this.needsUpdate(true);
}
}
}
@@ -167,8 +176,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
@Override
public boolean saveData(ClientMessage packet, GameClient gameClient) {
if (gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) {
- packet.readInt();
-
+ int argsLength = packet.readInt();
this.rewardTime = packet.readInt();
this.uniqueRewards = packet.readInt() == 1;
this.limit = packet.readInt();
@@ -196,11 +204,10 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
return false;
}
- WiredHandler.dropRewards(this.getId());
-
- packet.readString();
packet.readInt();
this.setDelay(packet.readInt());
+
+ WiredHandler.dropRewards(this.getId());
return true;
}
@@ -217,4 +224,24 @@ public class WiredEffectGiveReward extends InteractionWiredEffect {
protected long requiredCooldown() {
return 0;
}
+
+ static class JsonData {
+ int limit;
+ int given;
+ int reward_time;
+ boolean unique_rewards;
+ int limit_interval;
+ List rewards;
+ int delay;
+
+ public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List rewards, int delay) {
+ this.limit = limit;
+ this.given = given;
+ this.reward_time = reward_time;
+ this.unique_rewards = unique_rewards;
+ this.limit_interval = limit_interval;
+ this.rewards = rewards;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
index 91475710..5a326356 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java
@@ -1,5 +1,6 @@
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.Game;
import com.eu.habbo.habbohotel.items.Item;
@@ -9,8 +10,10 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.iterator.TObjectIntIterator;
import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap;
@@ -61,7 +64,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
if (iterator.value() < this.count) {
iterator.setValue(iterator.value() + 1);
- habbo.getHabboInfo().getGamePlayer().addScore(this.score);
+ habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
return true;
}
@@ -74,7 +77,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
this.data.put(new AbstractMap.SimpleEntry<>(game.getStartTime(), habbo.getHabboInfo().getId()), 1);
if (habbo.getHabboInfo().getGamePlayer() != null) {
- habbo.getHabboInfo().getGamePlayer().addScore(this.score);
+ habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);
}
return true;
@@ -85,17 +88,29 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.score + ";" + this.count + ";" + this.getDelay();
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.score, this.count, this.getDelay()));
}
@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 == 3) {
- this.score = Integer.valueOf(data[0]);
- this.count = Integer.valueOf(data[1]);
- this.setDelay(Integer.valueOf(data[2]));
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.score = data.score;
+ this.count = data.count;
+ this.setDelay(data.delay);
+ }
+ else {
+ String[] data = wiredData.split(";");
+
+ if (data.length == 3) {
+ this.score = Integer.valueOf(data[0]);
+ this.count = Integer.valueOf(data[1]);
+ this.setDelay(Integer.valueOf(data[2]));
+ }
+
+ this.needsUpdate(true);
}
}
@@ -147,14 +162,30 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.score = packet.readInt();
- this.count = packet.readInt();
+ int score = packet.readInt();
+
+ if(score < 1 || score > 100)
+ throw new WiredSaveException("Score is invalid");
+
+ int timesPerGame = packet.readInt();
+
+ if(timesPerGame < 1 || timesPerGame > 10)
+ throw new WiredSaveException("Times per game is invalid");
+
packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.score = score;
+ this.count = timesPerGame;
+ this.setDelay(delay);
return true;
}
@@ -163,4 +194,16 @@ public class WiredEffectGiveScore extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ int score;
+ int count;
+ int delay;
+
+ public JsonData(int score, int count, int delay) {
+ this.score = score;
+ this.count = count;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
index 738fc508..dcbc1481 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java
@@ -1,17 +1,20 @@
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.Game;
+import com.eu.habbo.habbohotel.games.GameState;
import com.eu.habbo.habbohotel.games.GameTeam;
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.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.incoming.wired.WiredSaveException;
import gnu.trove.map.hash.TIntIntHashMap;
import java.sql.ResultSet;
@@ -36,49 +39,52 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
+ for (Game game : room.getGames()) {
+ if (game != null && game.state.equals(GameState.RUNNING)) {
+ int c = this.startTimes.get(game.getStartTime());
- if (habbo != null) {
- Class extends Game> game = habbo.getHabboInfo().getCurrentGame();
+ if (c < this.count) {
+ GameTeam team = game.getTeam(this.teamColor);
- if (game != null) {
- Game g = room.getGame(game);
+ if (team != null) {
+ team.addTeamScore(this.points);
- if (g != null) {
- int c = this.startTimes.get(g.getStartTime());
-
- if (c < this.count) {
- GameTeam team = g.getTeam(this.teamColor);
-
- if (team != null) {
- team.addTeamScore(this.points);
-
- this.startTimes.put(g.getStartTime(), c++);
-
- return true;
- }
+ this.startTimes.put(game.getStartTime(), c + 1);
}
}
}
}
- return false;
+ return true;
}
@Override
public String getWiredData() {
- return this.points + ";" + this.count + ";" + this.teamColor.type + ";" + this.getDelay();
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.points, this.count, this.teamColor, this.getDelay()));
}
@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 == 4) {
- this.points = Integer.valueOf(data[0]);
- this.count = Integer.valueOf(data[1]);
- this.teamColor = GameTeamColors.values()[Integer.valueOf(data[2])];
- this.setDelay(Integer.valueOf(data[3]));
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.points = data.score;
+ this.count = data.count;
+ this.teamColor = data.team;
+ this.setDelay(data.delay);
+ }
+ else {
+ String[] data = set.getString("wired_data").split(";");
+
+ if (data.length == 4) {
+ this.points = Integer.valueOf(data[0]);
+ this.count = Integer.valueOf(data[1]);
+ this.teamColor = GameTeamColors.values()[Integer.valueOf(data[2])];
+ this.setDelay(Integer.valueOf(data[3]));
+ }
+
+ this.needsUpdate(true);
}
}
@@ -115,15 +121,51 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.points = packet.readInt();
- this.count = packet.readInt();
- this.teamColor = GameTeamColors.values()[packet.readInt()];
+ int points = packet.readInt();
+
+ if(points < 1 || points > 100)
+ throw new WiredSaveException("Points is invalid");
+
+ int timesPerGame = packet.readInt();
+
+ if(timesPerGame < 1 || timesPerGame > 10)
+ throw new WiredSaveException("Times per game is invalid");
+
+ int team = packet.readInt();
+
+ if(team < 1 || team > 4)
+ throw new WiredSaveException("Team is invalid");
+
packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.points = points;
+ this.count = timesPerGame;
+ this.teamColor = GameTeamColors.values()[team];
+ this.setDelay(delay);
+
return true;
}
+
+ static class JsonData {
+ int score;
+ int count;
+ GameTeamColors team;
+ int delay;
+
+ public JsonData(int score, int count, GameTeamColors team, int delay) {
+ this.score = score;
+ this.count = count;
+ this.team = team;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
index 3285865a..8d367009 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java
@@ -1,6 +1,8 @@
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.Game;
import com.eu.habbo.habbohotel.games.GameTeamColors;
import com.eu.habbo.habbohotel.games.wired.WiredGame;
import com.eu.habbo.habbohotel.items.Item;
@@ -10,8 +12,10 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -37,16 +41,19 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
- if (habbo.getHabboInfo().getGamePlayer() == null) {
- WiredGame game = (WiredGame) room.getGame(WiredGame.class);
+ WiredGame game = (WiredGame) room.getGameOrCreate(WiredGame.class);
- if (game == null) {
- game = new WiredGame(room);
- room.addGame(game);
- }
-
- return game.addHabbo(habbo, this.teamColor);
+ if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != this.teamColor))) {
+ // remove from current game
+ Game currentGame = room.getGame(habbo.getHabboInfo().getCurrentGame());
+ currentGame.removeHabbo(habbo);
}
+
+ if(habbo.getHabboInfo().getGamePlayer() == null) {
+ game.addHabbo(habbo, this.teamColor);
+ }
+
+ return true;
}
return false;
@@ -54,19 +61,30 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "\t" + this.teamColor.type + "";
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.teamColor, this.getDelay()));
}
@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 >= 1) {
- this.setDelay(Integer.valueOf(data[0]));
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.teamColor = data.team;
+ }
+ else {
+ String[] data = set.getString("wired_data").split("\t");
- if (data.length >= 2) {
- this.teamColor = GameTeamColors.values()[Integer.valueOf(data[1])];
+ if (data.length >= 1) {
+ this.setDelay(Integer.valueOf(data[0]));
+
+ if (data.length >= 2) {
+ this.teamColor = GameTeamColors.values()[Integer.valueOf(data[1])];
+ }
}
+
+ this.needsUpdate(true);
}
}
@@ -116,12 +134,22 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
+ packet.readInt();
+ int team = packet.readInt();
+
+ if(team < 1 || team > 4)
+ throw new WiredSaveException("Team is invalid");
+
packet.readInt();
- this.teamColor = GameTeamColors.values()[packet.readInt()];
- int unknownInt = packet.readInt();
packet.readString();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.teamColor = GameTeamColors.values()[team];
+ this.setDelay(delay);
return true;
}
@@ -130,4 +158,14 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ GameTeamColors team;
+ int delay;
+
+ public JsonData(GameTeamColors team, int delay) {
+ this.team = team;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
index 72897ebf..e0f2ecd2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java
@@ -12,8 +12,10 @@ 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.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
import com.eu.habbo.threading.runnables.RoomUnitKick;
import gnu.trove.procedure.TObjectProcedure;
@@ -69,24 +71,35 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "\t" + this.message;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- try {
- String[] data = set.getString("wired_data").split("\t");
+ String wiredData = set.getString("wired_data");
- if (data.length >= 1) {
- this.setDelay(Integer.valueOf(data[0]));
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.message = data.message;
+ }
+ else {
+ try {
+ String[] data = set.getString("wired_data").split("\t");
- if (data.length >= 2) {
- this.message = data[1];
+ if (data.length >= 1) {
+ this.setDelay(Integer.valueOf(data[0]));
+
+ if (data.length >= 2) {
+ this.message = data[1];
+ }
}
+ } catch (Exception e) {
+ this.message = "";
+ this.setDelay(0);
}
- } catch (Exception e) {
- this.message = "";
- this.setDelay(0);
+
+ this.needsUpdate(true);
}
}
@@ -135,11 +148,17 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.message = packet.readString();
+ String message = packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
+ this.setDelay(delay);
return true;
}
@@ -148,4 +167,14 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ String message;
+ int delay;
+
+ public JsonData(String message, int delay) {
+ this.message = message;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
index 248adcda..deff061e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java
@@ -1,5 +1,6 @@
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.Game;
import com.eu.habbo.habbohotel.games.wired.WiredGame;
@@ -10,8 +11,10 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import java.sql.ResultSet;
@@ -39,7 +42,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
Game game = room.getGame(habbo.getHabboInfo().getCurrentGame());
if (game == null) {
- game = room.getGame(WiredGame.class);
+ game = room.getGameOrCreate(WiredGame.class);
}
if (game != null) {
@@ -53,12 +56,20 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "";
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- this.setDelay(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.setDelay(data.delay);
+ }
+ else {
+ this.setDelay(Integer.valueOf(wiredData));
+ }
}
@Override
@@ -105,11 +116,24 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
packet.readInt();
- this.setDelay(packet.readInt());
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.setDelay(delay);
return true;
}
+
+ static class JsonData {
+ int delay;
+
+ public JsonData(int delay) {
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
index 6b337571..bb615d8d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java
@@ -3,18 +3,16 @@ 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.items.Item;
-import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
-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.rooms.RoomUnit;
+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;
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 com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger;
@@ -22,8 +20,11 @@ import org.slf4j.LoggerFactory;
import java.sql.ResultSet;
import java.sql.SQLException;
+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;
@@ -45,163 +46,94 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- THashSet tilesToUpdate = new THashSet<>(this.settings.size());
- //this.refresh();
if(this.settings.isEmpty())
- return false;
+ return true;
for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
+ HabboItem item = room.getHabboItem(setting.item_id);
if (item != null) {
if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) {
- if (!setting.state.equals(" ")) {
+ if (!setting.state.equals(" ") && !item.getExtradata().equals(setting.state)) {
item.setExtradata(setting.state);
- tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
+ room.updateItemState(item);
}
}
- int oldRotation = item.getRotation();
- boolean slideAnimation = true;
- double offsetZ = 0;
+ RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ double oldZ = item.getZ();
- if (this.direction && item.getRotation() != setting.rotation) {
- item.setRotation(setting.rotation);
- slideAnimation = false;
-
- room.scheduledTasks.add(() -> {
- room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation).forEach(t -> {
- room.updateBotsAt(t.x, t.y);
- room.updateHabbosAt(t.x, t.y);
- });
- room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation).forEach(t -> {
- room.updateBotsAt(t.x, t.y);
- room.updateHabbosAt(t.x, t.y);
- });
- });
+ if(this.direction && !this.position) {
+ if(item.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, item, setting.rotation, false) == FurnitureMovementError.NONE) {
+ room.moveFurniTo(item, oldLocation, setting.rotation, null, true);
+ }
}
+ else if(this.position) {
+ boolean slideAnimation = !this.direction || item.getRotation() == setting.rotation;
+ RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y);
+ int newRotation = this.direction ? setting.rotation : item.getRotation();
- RoomTile t = null;
-
- if (this.position) {
- t = room.getLayout().getTile((short) setting.x, (short) setting.y);
-
- if (t != null && t.state != RoomTileState.INVALID) {
- boolean canMove = true;
-
- if (t.x == item.getX() && t.y == item.getY() || room.hasHabbosAt(t.x, t.y)) {
- canMove = !(room.getTopItemAt(t.x, t.y) == item);
- slideAnimation = false;
- }
-
-
- if (canMove && !room.hasHabbosAt(t.x, t.y)) {
- THashSet tiles = room.getLayout().getTilesAt(t, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), setting.rotation);
- double highestZ = -1d;
- for (RoomTile tile : tiles) {
- if (tile.state == RoomTileState.INVALID) {
- highestZ = -1d;
- break;
- }
-
- if (item instanceof InteractionRoller && room.hasItemsAt(tile.x, tile.y)) {
- highestZ = -1d;
- break;
- }
-
- double stackHeight = room.getStackHeight(tile.x, tile.y, false, item);
- if (stackHeight > highestZ) {
- highestZ = stackHeight;
- }
- }
-
- if (highestZ != -1d) {
- tilesToUpdate.addAll(tiles);
-
- offsetZ = highestZ - item.getZ();
- double totalHeight = item.getZ() + offsetZ;
- if (totalHeight > 40) break;
- tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), oldRotation));
-
- if (!slideAnimation) {
- item.setX(t.x);
- item.setY(t.y);
- }
+ if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) {
+ if(room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
+ if(slideAnimation) {
+ room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
}
}
}
- if (slideAnimation && t != null) {
- room.sendComposer(new FloorItemOnRollerComposer(item, null, t, offsetZ, room).compose());
- } else {
- room.updateItem(item);
- }
-
- item.needsUpdate(true);
}
}
- room.updateTiles(tilesToUpdate);
-
return true;
}
@Override
public String getWiredData() {
this.refresh();
-
- StringBuilder data = new StringBuilder(this.settings.size() + ":");
-
- if (this.settings.isEmpty()) {
- data.append(";");
- } else {
- Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
-
- for (WiredMatchFurniSetting item : this.settings) {
- HabboItem i;
-
- if (room != null) {
- i = room.getHabboItem(item.itemId);
-
- if (i != null) {
- data.append(item.toString(this.checkForWiredResetPermission && i.allowWiredResetState())).append(";");
- }
- }
- }
- }
-
- data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0).append(":").append(this.getDelay());
-
- return data.toString();
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay()));
}
@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]);
-
- String[] items = data[1].split(";");
-
- for (int i = 0; i < items.length; i++) {
- try {
-
- 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])));
- }
-
- } catch (Exception e) {
- LOGGER.error("Caught exception", e);
- }
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.state = data.state;
+ this.direction = data.direction;
+ this.position = data.position;
+ this.settings.clear();
+ this.settings.addAll(data.items);
}
+ else {
+ String[] data = set.getString("wired_data").split(":");
- this.state = data[2].equals("1");
- this.direction = data[3].equals("1");
- this.position = data[4].equals("1");
- this.setDelay(Integer.valueOf(data[5]));
+ int itemCount = Integer.parseInt(data[0]);
+
+ String[] items = data[1].split(Pattern.quote(";"));
+
+ for (int i = 0; i < items.length; i++) {
+ try {
+
+ String[] stuff = items[i].split(Pattern.quote("-"));
+
+ 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])));
+ }
+
+ } catch (Exception e) {
+ LOGGER.error("Caught exception", e);
+ }
+ }
+
+ this.state = data[2].equals("1");
+ this.direction = data[3].equals("1");
+ this.position = data[4].equals("1");
+ this.setDelay(Integer.parseInt(data[5]));
+ this.needsUpdate(true);
+ }
}
@Override
@@ -227,7 +159,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
message.appendInt(this.settings.size());
for (WiredMatchFurniSetting item : this.settings)
- message.appendInt(item.itemId);
+ message.appendInt(item.item_id);
message.appendInt(this.getBaseItem().getSpriteId());
message.appendInt(this.getId());
@@ -243,36 +175,49 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
- this.settings.clear();
-
- //packet.readInt();
-
- int count;
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.state = packet.readInt() == 1;
- this.direction = packet.readInt() == 1;
- this.position = packet.readInt() == 1;
+ boolean setState = packet.readInt() == 1;
+ boolean setDirection = packet.readInt() == 1;
+ boolean setPosition = packet.readInt() == 1;
packet.readString();
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
if (room == null)
- return true;
+ throw new WiredSaveException("Trying to save wired in unloaded room");
- count = packet.readInt();
+ int itemsCount = packet.readInt();
- 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(), this.checkForWiredResetPermission && item.allowWiredResetState() ? item.getExtradata() : " ", item.getRotation(), item.getX(), item.getY()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newSettings = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY()));
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.state = setState;
+ this.direction = setDirection;
+ this.position = setPosition;
+ this.settings.clear();
+ this.settings.addAll(newSettings);
+ this.setDelay(delay);
return true;
}
@@ -284,7 +229,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
THashSet remove = new THashSet<>();
for (WiredMatchFurniSetting setting : this.settings) {
- HabboItem item = room.getHabboItem(setting.itemId);
+ HabboItem item = room.getHabboItem(setting.item_id);
if (item == null) {
remove.add(setting);
}
@@ -295,4 +240,40 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect {
}
}
}
+
+ @Override
+ public THashSet 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;
+ boolean position;
+ List items;
+ int delay;
+
+ public JsonData(boolean state, boolean direction, boolean position, List items, int delay) {
+ this.state = state;
+ this.direction = direction;
+ this.position = position;
+ this.items = items;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
index 556e56c3..76fe1ed9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java
@@ -12,11 +12,16 @@ 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;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
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;
@@ -44,64 +49,47 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
for (HabboItem item : this.items) {
RoomTile t = room.getLayout().getTile(item.getX(), item.getY());
- double shortest = 1000.0D;
- Habbo target = null;
-
- for (Habbo habbo : room.getHabbos()) {
- if (habbo.getRoomUnit().getCurrentLocation().distance(t) <= shortest) {
- shortest = habbo.getRoomUnit().getCurrentLocation().distance(t);
- target = habbo;
- }
- }
+ RoomUnit target = room.getRoomUnits().stream().min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t))).orElse(null);
if (target != null) {
- if (RoomLayout.tilesAdjecent(target.getRoomUnit().getCurrentLocation(), room.getLayout().getTile(item.getX(), item.getY())) && (target.getRoomUnit().getX() == item.getX() || target.getRoomUnit().getY() == item.getY())) {
- final Habbo finalTarget = target;
- Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, finalTarget.getRoomUnit(), room, new Object[]{item}), 500);
-
+ if (target.getCurrentLocation().distance(t) <= 1) {
+ Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, target, room, new Object[]{item}), 500);
continue;
}
int x = 0;
int y = 0;
- if (target.getRoomUnit().getX() == item.getX()) {
- if (item.getY() < target.getRoomUnit().getY())
+ if (target.getX() == item.getX()) {
+ if (item.getY() < target.getY())
y--;
else
y++;
- } else if (target.getRoomUnit().getY() == item.getY()) {
- if (item.getX() < target.getRoomUnit().getX())
+ } else if (target.getY() == item.getY()) {
+ if (item.getX() < target.getX())
x--;
else
x++;
- } else if (target.getRoomUnit().getX() - item.getX() > target.getRoomUnit().getY() - item.getY()) {
- if (target.getRoomUnit().getX() - item.getX() > 0)
+ } else if (target.getX() - item.getX() > target.getY() - item.getY()) {
+ if (target.getX() - item.getX() > 0)
x--;
else
x++;
} else {
- if (target.getRoomUnit().getY() - item.getY() > 0)
+ if (target.getY() - item.getY() > 0)
y--;
else
y++;
}
- RoomTile newTile = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y));
+ RoomTile newLocation = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y));
+ RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ double oldZ = item.getZ();
- if (newTile != null && newTile.state == RoomTileState.OPEN) {
- if (room.getLayout().tileExists(newTile.x, newTile.y)) {
- HabboItem topItem = room.getTopItemAt(newTile.x, newTile.y);
-
- if (topItem == null || topItem.getBaseItem().allowStack()) {
- double offsetZ = 0;
-
- if (topItem != null)
- offsetZ = topItem.getZ() + topItem.getBaseItem().getHeight() - item.getZ();
-
- room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offsetZ, room).compose());
- }
+ if(newLocation != null && newLocation.state != RoomTileState.INVALID && newLocation != oldLocation && room.furnitureFitsAt(newLocation, item, item.getRotation(), true) == FurnitureMovementError.NONE) {
+ if(room.moveFurniTo(item, newLocation, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
+ room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
}
}
@@ -111,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);
+ }
}
}
}
@@ -182,19 +178,35 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
+ int itemsCount = packet.readInt();
- this.items.clear();
-
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -203,4 +215,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
index bb7853c8..3b9367e2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java
@@ -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 items = new THashSet<>();
+ THashSet 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 itemIds;
+
+ public JsonData(int direction, int spacing, int delay, List itemIds) {
+ this.direction = direction;
+ this.spacing = spacing;
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
index 849a59b2..c069dc93 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java
@@ -11,6 +11,7 @@ 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.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import com.eu.habbo.threading.runnables.WiredCollissionRunnable;
import gnu.trove.map.hash.THashMap;
@@ -19,7 +20,9 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet;
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
@@ -82,7 +85,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- THashSet items = new THashSet();
+ THashSet items = new THashSet<>();
for (HabboItem item : this.items) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
@@ -103,7 +106,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
RoomUserRotation lastDirection = lastDirections.get(item.getId());
// 1. Check if any user is within 3 tiles from the item
- Habbo target = null; // closest found user
+ RoomUnit target = null; // closest found user
RoomLayout layout = room.getLayout();
boolean collided = false;
@@ -128,12 +131,12 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
if (startTile != null && layout.tileExists(startTile.x, startTile.y)) {
- THashSet habbosAtTile = room.getHabbosAt(startTile.x, startTile.y);
- if (habbosAtTile.size() > 0) {
- target = habbosAtTile.iterator().next();
+ Collection roomUnitsAtTile = room.getRoomUnitsAt(startTile);
+ if (roomUnitsAtTile.size() > 0) {
+ target = roomUnitsAtTile.iterator().next();
if (i == 0) { // i = 0 means right next to it
collided = true;
- Emulator.getThreading().run(new WiredCollissionRunnable(target.getRoomUnit(), room, new Object[]{item}));
+ Emulator.getThreading().run(new WiredCollissionRunnable(target, room, new Object[]{item}));
}
break;
}
@@ -145,23 +148,23 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
continue;
if (target != null) {
- if (target.getRoomUnit().getX() == item.getX()) {
- if (item.getY() < target.getRoomUnit().getY())
+ if (target.getX() == item.getX()) {
+ if (item.getY() < target.getY())
moveDirection = RoomUserRotation.SOUTH;
else
moveDirection = RoomUserRotation.NORTH;
- } else if (target.getRoomUnit().getY() == item.getY()) {
- if (item.getX() < target.getRoomUnit().getX())
+ } else if (target.getY() == item.getY()) {
+ if (item.getX() < target.getX())
moveDirection = RoomUserRotation.EAST;
else
moveDirection = RoomUserRotation.WEST;
- } else if (target.getRoomUnit().getX() - item.getX() > target.getRoomUnit().getY() - item.getY()) {
- if (target.getRoomUnit().getX() - item.getX() > 0)
+ } else if (target.getX() - item.getX() > target.getY() - item.getY()) {
+ if (target.getX() - item.getX() > 0)
moveDirection = RoomUserRotation.EAST;
else
moveDirection = RoomUserRotation.WEST;
} else {
- if (target.getRoomUnit().getY() - item.getY() > 0)
+ if (target.getY() - item.getY() > 0)
moveDirection = RoomUserRotation.SOUTH;
else
moveDirection = RoomUserRotation.NORTH;
@@ -213,13 +216,15 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
RoomTile newTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), moveDirection.getValue());
- if (newTile != null) {
- lastDirections.put(item.getId(), moveDirection);
+ RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ double oldZ = item.getZ();
- FurnitureMovementError error = room.furnitureFitsAt(newTile, item, item.getRotation());
- if (error == FurnitureMovementError.NONE) {
- double offset = room.getStackHeight(newTile.x, newTile.y, false, item) - item.getZ();
- room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offset, room).compose());
+ if(newTile != null) {
+ lastDirections.put(item.getId(), moveDirection);
+ if(newTile.state != RoomTileState.INVALID && newTile != oldLocation && room.furnitureFitsAt(newTile, item, item.getRotation(), true) == FurnitureMovementError.NONE) {
+ if (room.moveFurniTo(item, newTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) {
+ room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newTile, item.getZ(), 0, room).compose());
+ }
}
}
}
@@ -229,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.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);
- 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);
+ }
}
}
}
@@ -300,19 +314,36 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
- this.items.clear();
+ int itemsCount = packet.readInt();
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -321,4 +352,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
protected long requiredCooldown() {
return 495;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
index ae37a0f3..5928e671 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java
@@ -2,210 +2,141 @@ 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.items.ICycleable;
import com.eu.habbo.habbohotel.items.Item;
-import com.eu.habbo.habbohotel.items.interactions.InteractionRoller;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.rooms.*;
-import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboItem;
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.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
-import com.eu.habbo.messages.outgoing.rooms.items.FloorItemUpdateComposer;
import gnu.trove.set.hash.THashSet;
-import org.apache.commons.math3.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.awt.*;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMoveRotateFurni.class);
-public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
public static final WiredEffectType type = WiredEffectType.MOVE_ROTATE;
private final THashSet items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2);
private int direction;
private int rotation;
+ private THashSet itemCooldowns;
public WiredEffectMoveRotateFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
+ this.itemCooldowns = new THashSet<>();
}
public WiredEffectMoveRotateFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells);
+ this.itemCooldowns = new THashSet<>();
}
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
// remove items that are no longer in the room
- this.items.removeIf( item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
-
- THashSet tilesToUpdate = new THashSet<>(Math.min(this.items.size(), 10));
+ this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null);
for (HabboItem item : this.items) {
- //Handle rotation
- if (this.rotation > 0) {
- tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
- int newRotation = this.getNewRotation(item);
+ if(this.itemCooldowns.contains(item))
+ continue;
- //Verify if rotation result in a valid position
- FurnitureMovementError rotateError = room.furnitureFitsAt(room.getLayout().getTile(item.getX(), item.getY()), item, newRotation);
- if (item.getRotation() != newRotation && (rotateError.equals(FurnitureMovementError.TILE_HAS_HABBOS) || rotateError.equals(FurnitureMovementError.TILE_HAS_PETS) ||
- rotateError.equals(FurnitureMovementError.TILE_HAS_BOTS) || rotateError.equals(FurnitureMovementError.NONE)))
- {
- item.setRotation(newRotation);
- if(this.direction == 0) {
- tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()));
- room.sendComposer(new FloorItemUpdateComposer(item).compose());
- for (RoomTile t : tilesToUpdate) {
- room.updateHabbosAt(t.x, t.y);
- room.updateBotsAt(t.x, t.y);
- }
- }
- }
- }
+ int newRotation = this.rotation > 0 ? this.getNewRotation(item) : item.getRotation();
+ RoomTile newLocation = room.getLayout().getTile(item.getX(), item.getY());
+ RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY());
+ double oldZ = item.getZ();
- //handle movement
- if (this.direction > 0) {
+ if(this.direction > 0) {
RoomUserRotation moveDirection = this.getMovementDirection();
- boolean validMove = false;
- RoomLayout layout = room.getLayout();
- if (layout == null) return false;
-
- RoomTile newTile = layout.getTile(
- (short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))),
- (short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)))
+ newLocation = room.getLayout().getTile(
+ (short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))),
+ (short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0)))
);
+ }
- if (newTile != null) {
- boolean hasHabbos = false;
- for (Habbo habbo : room.getHabbosAt(newTile)) {
- hasHabbos = true;
- WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{item});
- }
+ boolean slideAnimation = item.getRotation() == newRotation;
- if (!hasHabbos && room.getStackHeight(newTile.x, newTile.y, true, item) != Short.MAX_VALUE) {
- java.awt.Rectangle rectangle = new Rectangle(newTile.x,
- newTile.y,
- item.getBaseItem().getWidth(),
- item.getBaseItem().getLength());
-
- double offset = -Short.MAX_VALUE;
- validMove = true;
- for (short x = (short) rectangle.x; x < rectangle.x + rectangle.getWidth(); x++) {
- if (!validMove) {
- break;
- }
-
- for (short y = (short) rectangle.y; y < rectangle.y + rectangle.getHeight(); y++) {
- RoomTile tile = layout.getTile(x, y);
- if (tile == null || tile.state == RoomTileState.INVALID || !tile.getAllowStack()) {
- validMove = false;
- break;
- }
-
- THashSet itemsAtNewTile = room.getItemsAt(tile);
- if (item instanceof InteractionRoller && !itemsAtNewTile.isEmpty()) {
- validMove = false;
- break;
- }
-
- ArrayList>> tileItems = new ArrayList<>(rectangle.width * rectangle.height);
- tileItems.add(Pair.create(tile, itemsAtNewTile));
- if (!item.canStackAt(room, tileItems)) {
- validMove = false;
- break;
- }
-
- HabboItem i = room.getTopItemAt(x, y, item);
- if (i != null && !i.getBaseItem().allowStack()) {
- validMove = false;
- break;
- }
-
- offset = Math.max(room.getStackHeight(newTile.x, newTile.y, false, item) - item.getZ(), offset);
-
- tilesToUpdate.add(tile);
- }
- }
- if (item.getZ() + offset > 40) {
- offset = 40 - item.getZ();
- }
-
- if (validMove) {
- if(this.rotation > 0) {
- item.setX(newTile.x);
- item.setY(newTile.y);
- item.setZ(item.getZ() + offset);
- room.sendComposer(new FloorItemUpdateComposer(item).compose());
- for (RoomTile t : tilesToUpdate) {
- room.updateHabbosAt(t.x, t.y);
- room.updateBotsAt(t.x, t.y);
- }
- }
- else {
- room.sendComposer(new FloorItemOnRollerComposer(item, null, newTile, offset, room).compose());
- }
- }
+ FurnitureMovementError furniMoveTest = room.furnitureFitsAt(newLocation, item, newRotation, true);
+ if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && (furniMoveTest == FurnitureMovementError.NONE || ((furniMoveTest == FurnitureMovementError.TILE_HAS_BOTS || furniMoveTest == FurnitureMovementError.TILE_HAS_HABBOS || furniMoveTest == FurnitureMovementError.TILE_HAS_PETS) && newLocation == oldLocation))) {
+ if(room.furnitureFitsAt(newLocation, item, newRotation, false) == FurnitureMovementError.NONE && room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) {
+ this.itemCooldowns.add(item);
+ if(slideAnimation) {
+ room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose());
}
}
}
}
- if (!tilesToUpdate.isEmpty()) {
- room.updateTiles(tilesToUpdate);
- }
-
return true;
}
@Override
public String getWiredData() {
- THashSet items = new THashSet<>(this.items.size() / 2);
+ THashSet 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) {
- }
-
- 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);
+ }
}
}
}
@@ -225,7 +156,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
@Override
public void serializeWiredData(ServerMessage message, Room room) {
- THashSet items = new THashSet<>(this.items.size() / 2);
+ THashSet items = new THashSet<>();
for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
@@ -268,6 +199,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
packet.readString();
int count = packet.readInt();
+ if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false;
this.items.clear();
for (int i = 0; i < count; i++) {
@@ -282,30 +214,78 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
/**
* Returns a new rotation for an item based on the wired options
- * @param item
+ *
+ * @param item HabboItem
* @return new rotation
*/
private int getNewRotation(HabboItem item) {
int rotationToAdd = 0;
- if (this.rotation == 1) {
- rotationToAdd = 2;
- } else if (this.rotation == 2) {
- rotationToAdd = 6;
+
+ if(item.getMaximumRotations() == 2) {
+ return item.getRotation() == 0 ? 4 : 0;
}
- //Random rotation
- else if (this.rotation == 3) {
- if (Emulator.getRandom().nextInt(2) == 1) {
- rotationToAdd = 2;
- } else {
- rotationToAdd = 6;
+ else if(item.getMaximumRotations() == 1) {
+ return item.getRotation();
+ }
+ else if(item.getMaximumRotations() > 4) {
+ if (this.rotation == 1) {
+ return item.getRotation() == item.getMaximumRotations() - 1 ? 0 : item.getRotation() + 1;
+ } else if (this.rotation == 2) {
+ return item.getRotation() > 0 ? item.getRotation() - 1 : item.getMaximumRotations() - 1;
+ } else if (this.rotation == 3) { //Random rotation
+ THashSet possibleRotations = new THashSet<>();
+ for (int i = 0; i < item.getMaximumRotations(); i++)
+ {
+ possibleRotations.add(i);
+ }
+
+ possibleRotations.remove(item.getRotation());
+
+ if(possibleRotations.size() > 0) {
+ int index = Emulator.getRandom().nextInt(possibleRotations.size());
+ Iterator iter = possibleRotations.iterator();
+ for (int i = 0; i < index; i++) {
+ iter.next();
+ }
+ return iter.next();
+ }
+ }
+ }
+ else {
+ if (this.rotation == 1) {
+ return (item.getRotation() + 2) % 8;
+ } else if (this.rotation == 2) {
+ int rot = (item.getRotation() - 2) % 8;
+ if(rot < 0) {
+ rot += 8;
+ }
+ return rot;
+ } else if (this.rotation == 3) { //Random rotation
+ THashSet possibleRotations = new THashSet<>();
+ for (int i = 0; i < item.getMaximumRotations(); i++)
+ {
+ possibleRotations.add(i * 2);
+ }
+
+ possibleRotations.remove(item.getRotation());
+
+ if(possibleRotations.size() > 0) {
+ int index = Emulator.getRandom().nextInt(possibleRotations.size());
+ Iterator iter = possibleRotations.iterator();
+ for (int i = 0; i < index; i++) {
+ iter.next();
+ }
+ return iter.next();
+ }
}
}
- return ((item.getRotation() + rotationToAdd) % 8) % (item.getBaseItem().getWidth() > 1 || item.getBaseItem().getLength() > 1 ? 4 : 8);
+ return item.getRotation();
}
/**
* Returns the direction of movement based on the wired settings
+ *
* @return direction
*/
private RoomUserRotation getMovementDirection() {
@@ -319,20 +299,35 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
movemementDirection = RoomUserRotation.WEST;
}
} else if (this.direction == 3) {
- if (Emulator.getRandom().nextInt(2) == 1) {
- movemementDirection = RoomUserRotation.NORTH;
- } else {
+ if (Emulator.getRandom().nextInt(2) != 1) {
movemementDirection = RoomUserRotation.SOUTH;
}
} else if (this.direction == 4) {
movemementDirection = RoomUserRotation.SOUTH;
} else if (this.direction == 5) {
movemementDirection = RoomUserRotation.EAST;
- } else if (this.direction == 6) {
- movemementDirection = RoomUserRotation.NORTH;
} else if (this.direction == 7) {
movemementDirection = RoomUserRotation.WEST;
}
return movemementDirection;
}
-}
\ No newline at end of file
+
+ @Override
+ public void cycle(Room room) {
+ this.itemCooldowns.clear();
+ }
+
+ static class JsonData {
+ int direction;
+ int rotation;
+ int delay;
+ List itemIds;
+
+ public JsonData(int direction, int rotation, int delay, List itemIds) {
+ this.direction = direction;
+ this.rotation = rotation;
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
index 27a1d2b3..39788018 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
index 5d6f6cfe..583e4f6a 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
index ebd7254a..304703f1 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java
@@ -14,6 +14,7 @@ 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.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer;
import com.eu.habbo.threading.runnables.RoomUnitTeleport;
import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer;
@@ -25,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;
@@ -78,6 +80,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
}
}
+ Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500));
Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY);
}
@@ -127,19 +130,36 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
- this.items.clear();
+ int itemsCount = packet.readInt();
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -162,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);
+ }
}
}
}
@@ -213,4 +241,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect {
protected long requiredCooldown() {
return 50L;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
index e602c042..05eef1f3 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java
@@ -3,12 +3,20 @@ 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.items.Item;
-import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable;
-import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
-import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
+import com.eu.habbo.habbohotel.items.interactions.*;
+import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
+import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard;
+import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTeamItem;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiPuck;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock;
+import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile;
+import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
+import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
+import com.eu.habbo.habbohotel.items.interactions.pets.*;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.Habbo;
@@ -17,6 +25,7 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger;
@@ -26,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);
@@ -34,6 +44,46 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
private final THashSet items;
+ private static final List> FORBIDDEN_TYPES = new ArrayList>() {
+ {
+ this.add(InteractionWired.class);
+ this.add(InteractionTeleport.class);
+ this.add(InteractionPushable.class);
+ this.add(InteractionTagPole.class);
+ this.add(InteractionTagField.class);
+ this.add(InteractionCrackable.class);
+ this.add(InteractionGameScoreboard.class);
+ this.add(InteractionGameGate.class);
+ this.add(InteractionFreezeTile.class);
+ this.add(InteractionFreezeBlock.class);
+ this.add(InteractionFreezeExitTile.class);
+ this.add(InteractionBattleBanzaiTeleporter.class);
+ this.add(InteractionBattleBanzaiTile.class);
+ this.add(InteractionMonsterPlantSeed.class);
+ this.add(InteractionPetBreedingNest.class);
+ this.add(InteractionPetDrink.class);
+ this.add(InteractionPetFood.class);
+ this.add(InteractionPetToy.class);
+ this.add(InteractionBadgeDisplay.class);
+ this.add(InteractionClothing.class);
+ this.add(InteractionVendingMachine.class);
+ this.add(InteractionGift.class);
+ this.add(InteractionPressurePlate.class);
+ this.add(InteractionMannequin.class);
+ this.add(InteractionGymEquipment.class);
+ this.add(InteractionHopper.class);
+ this.add(InteractionObstacle.class);
+ this.add(InteractionOneWayGate.class);
+ this.add(InteractionPuzzleBox.class);
+ this.add(InteractionRoller.class);
+ this.add(InteractionSwitch.class);
+ this.add(InteractionTent.class);
+ this.add(InteractionTrap.class);
+ this.add(InteractionTrophy.class);
+ this.add(InteractionWater.class);
+ }
+ };
+
public WiredEffectToggleFurni(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
this.items = new THashSet<>();
@@ -92,24 +142,36 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
- this.items.clear();
+ int itemsCount = packet.readInt();
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt());
-
- if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable)
- continue;
-
- this.items.add(item);
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -122,7 +184,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
THashSet itemsToRemove = new THashSet<>();
for (HabboItem item : this.items) {
- if (item == null || item.getRoomId() == 0 || item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile) {
+ if (item == null || item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) {
itemsToRemove.add(item);
continue;
}
@@ -132,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) {
}
@@ -151,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);
+ }
}
}
}
@@ -195,4 +270,14 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect {
public WiredEffectType getType() {
return type;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
index 98b41137..4fbd9203 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java
@@ -3,11 +3,18 @@ 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.items.Item;
-import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable;
-import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
-import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
+import com.eu.habbo.habbohotel.items.interactions.*;
+import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate;
+import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard;
import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter;
+import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile;
import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock;
+import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile;
+import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile;
+import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField;
+import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole;
+import com.eu.habbo.habbohotel.items.interactions.pets.*;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.users.HabboItem;
@@ -15,6 +22,7 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
import org.slf4j.Logger;
@@ -24,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);
@@ -32,6 +41,46 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
private final THashSet items = new THashSet<>();
+ private static final List> FORBIDDEN_TYPES = new ArrayList>() {
+ {
+ this.add(InteractionWired.class);
+ this.add(InteractionTeleport.class);
+ this.add(InteractionPushable.class);
+ this.add(InteractionTagPole.class);
+ this.add(InteractionTagField.class);
+ this.add(InteractionCrackable.class);
+ this.add(InteractionGameScoreboard.class);
+ this.add(InteractionGameGate.class);
+ this.add(InteractionFreezeTile.class);
+ this.add(InteractionFreezeBlock.class);
+ this.add(InteractionFreezeExitTile.class);
+ this.add(InteractionBattleBanzaiTeleporter.class);
+ this.add(InteractionBattleBanzaiTile.class);
+ this.add(InteractionMonsterPlantSeed.class);
+ this.add(InteractionPetBreedingNest.class);
+ this.add(InteractionPetDrink.class);
+ this.add(InteractionPetFood.class);
+ this.add(InteractionPetToy.class);
+ this.add(InteractionBadgeDisplay.class);
+ this.add(InteractionClothing.class);
+ this.add(InteractionVendingMachine.class);
+ this.add(InteractionGift.class);
+ this.add(InteractionPressurePlate.class);
+ this.add(InteractionMannequin.class);
+ this.add(InteractionGymEquipment.class);
+ this.add(InteractionHopper.class);
+ this.add(InteractionObstacle.class);
+ this.add(InteractionOneWayGate.class);
+ this.add(InteractionPuzzleBox.class);
+ this.add(InteractionRoller.class);
+ this.add(InteractionSwitch.class);
+ this.add(InteractionTent.class);
+ this.add(InteractionTrap.class);
+ this.add(InteractionTrophy.class);
+ this.add(InteractionWater.class);
+ }
+ };
+
public WiredEffectToggleRandom(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem);
}
@@ -88,24 +137,36 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
- this.items.clear();
+ int itemsCount = packet.readInt();
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt());
-
- if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
- continue;
-
- this.items.add(item);
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -115,7 +176,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
THashSet items = this.items;
for (HabboItem item : items) {
- if (item.getRoomId() == 0) {
+ if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) {
this.items.remove(item);
continue;
}
@@ -132,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);
+ }
}
}
}
@@ -176,4 +248,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
public WiredEffectType getType() {
return type;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
index 41a38dd8..db37872b 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java
@@ -13,6 +13,7 @@ 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.incoming.wired.WiredSaveException;
import gnu.trove.procedure.TObjectProcedure;
import gnu.trove.set.hash.THashSet;
@@ -20,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;
@@ -83,19 +85,36 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
packet.readString();
- this.items.clear();
+ int itemsCount = packet.readInt();
- int count = packet.readInt();
-
- for (int i = 0; i < count; i++) {
- this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()));
+ if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) {
+ throw new WiredSaveException("Too many furni selected");
}
- this.setDelay(packet.readInt());
+ List newItems = new ArrayList<>();
+
+ for (int i = 0; i < itemsCount; i++) {
+ int itemId = packet.readInt();
+ HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId);
+
+ if(it == null)
+ throw new WiredSaveException(String.format("Item %s not found", itemId));
+
+ newItems.add(it);
+ }
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.items.clear();
+ this.items.addAll(newItems);
+ this.setDelay(delay);
return true;
}
@@ -138,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);
+ }
}
}
}
@@ -184,4 +211,14 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
protected long requiredCooldown() {
return 250;
}
+
+ static class JsonData {
+ int delay;
+ List itemIds;
+
+ public JsonData(int delay, List itemIds) {
+ this.delay = delay;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
index 3cc5872a..56d6f35e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java
@@ -5,14 +5,16 @@ import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect;
import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger;
-import com.eu.habbo.habbohotel.rooms.Room;
-import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
-import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
-import com.eu.habbo.habbohotel.rooms.RoomUnit;
+import com.eu.habbo.habbohotel.permissions.Permission;
+import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.users.Habbo;
+import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting;
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.ClientMessage;
import com.eu.habbo.messages.ServerMessage;
+import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer;
import gnu.trove.procedure.TObjectProcedure;
@@ -68,15 +70,25 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
}
@Override
- public boolean saveData(ClientMessage packet, GameClient gameClient) {
+ public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException {
packet.readInt();
- this.message = Emulator.getGameEnvironment().getWordFilter().filter(packet.readString(), null);
- if (this.message.length() > 100) {
- this.message = "";
+ String message = packet.readString();
+
+ if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) {
+ message = Emulator.getGameEnvironment().getWordFilter().filter(message, null);
+ message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100)));
}
+
packet.readInt();
- this.setDelay(packet.readInt());
+
+ int delay = packet.readInt();
+
+ if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20))
+ throw new WiredSaveException("Delay too long");
+
+ this.message = message;
+ this.setDelay(delay);
return true;
}
@@ -87,7 +99,9 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
- habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED)));
+ String msg = this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + "");
+ habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED)));
+ Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg }));
if (habbo.getRoomUnit().isIdle()) {
habbo.getRoomUnit().getRoom().unIdle(habbo);
@@ -107,17 +121,27 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
@Override
public String getWiredData() {
- return this.getDelay() + "\t" + this.message;
+ return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay()));
}
@Override
public void loadWiredData(ResultSet set, Room room) throws SQLException {
- String wireData = set.getString("wired_data");
- this.message = "";
+ String wiredData = set.getString("wired_data");
- if (wireData.split("\t").length >= 2) {
- super.setDelay(Integer.valueOf(wireData.split("\t")[0]));
- this.message = wireData.split("\t")[1];
+ if(wiredData.startsWith("{")) {
+ JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
+ this.setDelay(data.delay);
+ this.message = data.message;
+ }
+ else {
+ this.message = "";
+
+ if (wiredData.split("\t").length >= 2) {
+ super.setDelay(Integer.valueOf(wiredData.split("\t")[0]));
+ this.message = wiredData.split("\t")[1];
+ }
+
+ this.needsUpdate(true);
}
}
@@ -136,4 +160,14 @@ public class WiredEffectWhisper extends InteractionWiredEffect {
public boolean requiresTriggeringUser() {
return true;
}
+
+ static class JsonData {
+ String message;
+ int delay;
+
+ public JsonData(String message, int delay) {
+ this.message = message;
+ this.delay = delay;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
index 0017efe8..8f859fd2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java
@@ -68,7 +68,7 @@ public class WiredBlob extends InteractionDefault {
GamePlayer player = habbo.getHabboInfo().getGamePlayer();
if (player != null) {
- player.addScore(this.POINTS_REWARD);
+ player.addScore(this.POINTS_REWARD, true);
BattleBanzaiGame battleBanzaiGame = (BattleBanzaiGame) room.getGame(BattleBanzaiGame.class);
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java
new file mode 100644
index 00000000..6db447f7
--- /dev/null
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java
@@ -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 getMatchFurniSettings();
+ public boolean shouldMatchState();
+ public boolean shouldMatchRotation();
+ public boolean shouldMatchPosition();
+}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
index 414412eb..f6364641 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
index 4bcec897..751d21c7 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
index 73c543c3..596fbc8f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java
@@ -21,11 +21,12 @@ 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);
- public final static WiredTriggerType type = WiredTriggerType.BOT_REACHED_STF;
+ public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
private THashSet items;
private String botName = "";
@@ -73,7 +74,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
message.appendString(this.botName);
message.appendInt(0);
message.appendInt(0);
- message.appendInt(this.getType().code);
+ message.appendInt(WiredTriggerType.BOT_REACHED_STF.code);
if (!this.isTriggeredByRoomUnit()) {
List invalidTriggers = new ArrayList<>();
@@ -114,54 +115,55 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- List bots = room.getBots(this.botName);
-
- for (Bot bot : bots) {
- if (bot.getRoomUnit().equals(roomUnit)) {
- for (Object o : stuff) {
- if (this.items.contains(o))
- return true;
- }
+ if (stuff.length >= 1) {
+ if (stuff[0] instanceof HabboItem) {
+ return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
}
-
return false;
}
@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);
+ }
}
}
}
@@ -172,4 +174,14 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger {
this.items.clear();
this.botName = "";
}
+
+ static class JsonData {
+ String botName;
+ List itemIds;
+
+ public JsonData(String botName, List itemIds) {
+ this.botName = botName;
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
index 7da199f7..0e7b22fd 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java
@@ -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;
@@ -57,26 +58,26 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- if (stuff.length == 0)
- return false;
-
- List bots = room.getBots(this.botName);
-
- for (Bot bot : bots) {
- if (bot.getRoomUnit().equals(stuff[0]))
- return true;
- }
- return false;
+ return room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit);
}
@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
@@ -88,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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
index c31b571a..f97f332f 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java
@@ -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 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 itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
index 69175e52..9a1400b2 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
index 9a98f41c..f3b90ae3 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java
@@ -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;
@@ -28,14 +29,11 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
- Habbo habbo = room.getHabbo(roomUnit);
-
- if (habbo != null) {
- if (this.key.length() > 0) {
- if (stuff[0] instanceof String) {
- if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) {
- return !this.ownerOnly || room.getOwnerId() == habbo.getHabboInfo().getId();
- }
+ if (this.key.length() > 0) {
+ if (stuff[0] instanceof String) {
+ if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) {
+ Habbo habbo = room.getHabbo(roomUnit);
+ return !this.ownerOnly || (habbo != null && room.getOwnerId() == habbo.getHabboInfo().getId());
}
}
}
@@ -44,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];
+ }
}
}
@@ -96,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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
index 0e05ba01..64e9dae9 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java
@@ -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 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 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 itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
index 1ebad4c9..257f23bb 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java
@@ -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 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 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 itemIds;
+
+ public JsonData(List itemIds) {
+ this.itemIds = itemIds;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
index a0f693c9..36d48b3e 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
index ff3f9688..ad93a09d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
index b8fc74dd..1f558d88 100644
--- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
+++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java
@@ -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;
+ }
+ }
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java
index 59c6083a..db3c357c 100644
--- a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java
+++ b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java
@@ -167,18 +167,6 @@ public class Messenger {
return map;
}
- public static int friendLimit(Habbo habbo) {
- if (habbo.hasPermission("acc_infinite_friends")) {
- return Integer.MAX_VALUE;
- }
-
- if (habbo.getHabboStats().hasActiveClub()) {
- return MAXIMUM_FRIENDS_HC;
- }
-
- return MAXIMUM_FRIENDS;
- }
-
public static void checkFriendSizeProgress(Habbo habbo) {
int progress = habbo.getHabboStats().getAchievementProgress(Emulator.getGameEnvironment().getAchievementManager().getAchievement("FriendListSize"));
diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java
index c891286e..2a65ba4a 100644
--- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java
+++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java
@@ -54,7 +54,7 @@ public class ModToolManager {
if (userId <= 0)
return;
- try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.*, users_settings.*, permissions.rank_name, permissions.id as rank_id FROM users INNER JOIN users_settings ON users.id = users_settings.user_id INNER JOIN permissions ON permissions.id = users.rank WHERE users.id = ? LIMIT 1")) {
+ try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.*, users_settings.*, permissions.rank_name, permissions.acc_hide_mail AS hide_mail, permissions.id AS rank_id FROM users INNER JOIN users_settings ON users.id = users_settings.user_id INNER JOIN permissions ON permissions.id = users.rank WHERE users.id = ? LIMIT 1")) {
statement.setInt(1, userId);
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
@@ -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;
}
diff --git a/src/main/java/com/eu/habbo/habbohotel/permissions/Permission.java b/src/main/java/com/eu/habbo/habbohotel/permissions/Permission.java
index 5dfdd12f..469f9072 100644
--- a/src/main/java/com/eu/habbo/habbohotel/permissions/Permission.java
+++ b/src/main/java/com/eu/habbo/habbohotel/permissions/Permission.java
@@ -6,6 +6,7 @@ public class Permission {
public static String ACC_EMPTY_OTHERS = "acc_empty_others";
public static String ACC_ENABLE_OTHERS = "acc_enable_others";
public static String ACC_SEE_WHISPERS = "acc_see_whispers";
+ public static String ACC_SEE_TENTCHAT = "acc_see_tentchat";
public static String ACC_SUPERWIRED = "acc_superwired";
public static String ACC_SUPPORTTOOL = "acc_supporttool";
public static String ACC_UNKICKABLE = "acc_unkickable";
diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java
index d5e13742..afd7e035 100644
--- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java
+++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java
@@ -578,6 +578,7 @@ public class Pet implements ISerialize, Runnable {
this.addHappyness(10);
this.addExperience(10);
this.addRespect();
+ this.needsUpdate = true;
if (habbo != null) {
habbo.getHabboStats().petRespectPointsToGive--;
diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
index 9a0803fb..58321d7d 100644
--- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
+++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java
@@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
+import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.VisitorBot;
import com.eu.habbo.habbohotel.commands.CommandHandler;
@@ -115,6 +116,8 @@ public class Room implements Comparable, ISerialize, Runnable {
public static int IDLE_CYCLES_KICK = 480;
public static String PREFIX_FORMAT = "[%prefix%] ";
public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1;
+ public static boolean MUTEAREA_CAN_WHISPER = false;
+ public static double MAXIMUM_FURNI_HEIGHT = 40d;
static {
for (int i = 1; i <= 3; i++) {
@@ -380,6 +383,11 @@ public class Room implements Comparable, 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));
@@ -565,12 +573,14 @@ public class Room implements Comparable, ISerialize, Runnable {
return RoomTileState.INVALID;
RoomTileState result = RoomTileState.OPEN;
- HabboItem highestItem = null;
- HabboItem lowestChair = this.getLowestChair(tile);
+ //HabboItem highestItem = null;
+ //HabboItem lowestChair = this.getLowestChair(tile);
THashSet items = this.getItemsAt(tile);
if (items == null) return RoomTileState.INVALID;
+ HabboItem tallestItem = null;
+
for (HabboItem item : items) {
if (exclude != null && item == exclude) continue;
@@ -578,13 +588,16 @@ public class Room implements Comparable, ISerialize, Runnable {
return RoomTileState.LAY;
}
- if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
+ /*if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
continue;
- highestItem = item;
- if (result == RoomTileState.OPEN) {
- result = this.checkStateForItem(item, tile);
- }
+ highestItem = item;*/
+
+ if(tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item))
+ continue;
+
+ result = this.checkStateForItem(item, tile);
+ tallestItem = item;
/*if (lowestChair != null && item.getZ() > lowestChair.getZ() + 1.5) {
continue;
@@ -601,7 +614,7 @@ public class Room implements Comparable, ISerialize, Runnable {
}*/
}
- if (lowestChair != null) return RoomTileState.SIT;
+ //if (lowestChair != null) return RoomTileState.SIT;
return result;
}
@@ -750,13 +763,20 @@ public class Room implements Comparable, ISerialize, Runnable {
THashSet roomUnits = new THashSet<>();
for (Habbo habbo : habbos) {
+ double oldZ = habbo.getRoomUnit().getZ();
+ RoomUserRotation oldRotation = habbo.getRoomUnit().getBodyRotation();
double z = habbo.getRoomUnit().getCurrentLocation().getStackHeight();
+ boolean updated = false;
- if ((item == null && !habbo.getRoomUnit().cmdSit) || (item != null && !item.getBaseItem().allowSit()))
+ if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().cmdSit) || (item != null && !item.getBaseItem().allowSit()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
+ updated = true;
+ }
- if ((item == null && !habbo.getRoomUnit().cmdLay) || (item != null && !item.getBaseItem().allowLay()))
+ if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().cmdLay) || (item != null && !item.getBaseItem().allowLay()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
+ updated = true;
+ }
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
habbo.getRoomUnit().setZ(item.getZ());
@@ -766,12 +786,16 @@ public class Room implements Comparable, ISerialize, Runnable {
habbo.getRoomUnit().setZ(z);
habbo.getRoomUnit().setPreviousLocationZ(z);
}
- roomUnits.add(habbo.getRoomUnit());
+
+ if(habbo.getRoomUnit().getCurrentLocation().is(x, y) && (oldZ != z || updated || oldRotation != habbo.getRoomUnit().getBodyRotation())) {
+ habbo.getRoomUnit().statusUpdate(true);
+ //roomUnits.add(habbo.getRoomUnit());
+ }
}
- if (!roomUnits.isEmpty()) {
+ /*if (!roomUnits.isEmpty()) {
this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose());
- }
+ }*/
}
public void updateBotsAt(short x, short y) {
@@ -962,7 +986,6 @@ public class Room implements Comparable, ISerialize, Runnable {
Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
}
- @SuppressWarnings("NullableProblems")
@Override
public int compareTo(Room o) {
if (o.getUserCount() != this.getUserCount()) {
@@ -1187,8 +1210,11 @@ public class Room implements Comparable, 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();
@@ -1204,6 +1230,19 @@ public class Room implements Comparable, ISerialize, Runnable {
}
}
+ if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting")) {
+ //Check if the user isn't the owner id
+ if (this.ownerId != habbo.getHabboInfo().getId()) {
+ //Check if the time already have 1 minute (120 / 2 = 60s)
+ if (habbo.getRoomUnit().getTimeInRoom() >= 120) {
+ AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"));
+ habbo.getRoomUnit().resetTimeInRoom();
+ } else {
+ habbo.getRoomUnit().increaseTimeInRoom();
+ }
+ }
+ }
+
if (habbo.getHabboStats().mutedBubbleTracker && habbo.getHabboStats().allowTalk()) {
habbo.getHabboStats().mutedBubbleTracker = false;
this.sendComposer(new RoomUserIgnoredComposer(habbo, RoomUserIgnoredComposer.UNIGNORED).compose());
@@ -1397,7 +1436,7 @@ public class Room implements Comparable, ISerialize, Runnable {
roomUserRolledEvent = new UserRolledEvent(null, null, null);
}
- ArrayList unitsOnTile = new ArrayList(rollerTile.getUnits());
+ ArrayList unitsOnTile = new ArrayList<>(rollerTile.getUnits());
for (RoomUnit unit : rollerTile.getUnits()) {
if (unit.getRoomUnitType() == RoomUnitType.PET) {
@@ -1408,7 +1447,7 @@ public class Room implements Comparable, ISerialize, Runnable {
}
}
- HabboItem nextTileChair = this.getLowestChair(tileInFront);
+ HabboItem nextTileChair = this.getTallestChair(tileInFront);
THashSet usersRolledThisTile = new THashSet<>();
@@ -1445,7 +1484,7 @@ public class Room implements Comparable, ISerialize, Runnable {
tile.setStackHeight(ridingUnit.getZ() + zOffset);
rolledUnitIds.add(ridingUnit.getId());
updatedUnit.remove(ridingUnit);
- messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, tile.getStackHeight() + (nextTileChair != null ? -1 : 0), room));
+ messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, tile.getStackHeight(), room));
isRiding = true;
}
}
@@ -1454,16 +1493,16 @@ public class Room implements Comparable, ISerialize, Runnable {
usersRolledThisTile.add(unit.getId());
rolledUnitIds.add(unit.getId());
updatedUnit.remove(unit);
- messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tile, tile.getStackHeight() + (isRiding ? 1 : 0) + (nextTileChair != null ? -1 : 0), room));
+ messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tile, tile.getStackHeight() + (isRiding ? 1 : 0), room));
if (itemsOnRoller.isEmpty()) {
HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y);
- if (item != null && itemsNewTile.contains(item)) {
+ if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) {
Emulator.getThreading().run(() -> {
if (unit.getGoal() == rollerTile) {
try {
- item.onWalkOn(unit, room, null);
+ item.onWalkOn(unit, room, new Object[] { rollerTile, tileInFront });
} catch (Exception e) {
LOGGER.error("Caught exception", e);
}
@@ -1602,23 +1641,22 @@ public class Room implements Comparable, ISerialize, Runnable {
}
if (!unit.isWalking() && !unit.cmdSit) {
- HabboItem topItem = this.getLowestChair(this.getLayout().getTile(unit.getX(), unit.getY()));
+ RoomTile thisTile = this.getLayout().getTile(unit.getX(), unit.getY());
+ HabboItem topItem = this.getTallestChair(thisTile);
if (topItem == null || !topItem.getBaseItem().allowSit()) {
if (unit.hasStatus(RoomUnitStatus.SIT)) {
unit.removeStatus(RoomUnitStatus.SIT);
update = true;
}
- } else {
- if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate) {
- this.dance(unit, DanceType.NONE);
- //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
- unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + "");
- unit.setZ(topItem.getZ());
- unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
- unit.sitUpdate = false;
- return true;
- }
+ } else if (thisTile.state == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate)) {
+ this.dance(unit, DanceType.NONE);
+ //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
+ unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + "");
+ unit.setZ(topItem.getZ());
+ unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
+ unit.sitUpdate = false;
+ return true;
}
}
}
@@ -1946,7 +1984,7 @@ public class Room implements Comparable, ISerialize, Runnable {
if (extraData.length == 4) {
if (extraData[0].equalsIgnoreCase("1")) {
- return Color.getHSBColor(Integer.valueOf(extraData[1]), Integer.valueOf(extraData[2]), Integer.valueOf(extraData[3]));
+ return Color.getHSBColor(Integer.parseInt(extraData[1]), Integer.parseInt(extraData[2]), Integer.parseInt(extraData[3]));
}
}
}
@@ -2162,7 +2200,7 @@ public class Room implements Comparable, ISerialize, Runnable {
synchronized (this.games) {
for (Game game : this.games) {
- if (game != null && gameType.isInstance(game)) {
+ if (gameType.isInstance(game)) {
return game;
}
}
@@ -2171,6 +2209,20 @@ public class Room implements Comparable, ISerialize, Runnable {
return null;
}
+ public Game getGameOrCreate(Class extends Game> gameType) {
+ Game game = this.getGame(gameType);
+ if(game == null) {
+ try {
+ game = gameType.getDeclaredConstructor(Room.class).newInstance(this);
+ this.addGame(game);
+ } catch (Exception e) {
+ LOGGER.error("Error getting game " + gameType.getName(), e);
+ }
+ }
+
+ return game;
+ }
+
public ConcurrentSet getGames() {
return this.games;
}
@@ -2375,7 +2427,10 @@ public class Room implements Comparable, ISerialize, Runnable {
this.roomSpecialTypes.addUndefined(item);
} else if (item instanceof InteractionSnowboardSlope) {
this.roomSpecialTypes.addUndefined(item);
+ } else if (item instanceof InteractionFireworks) {
+ this.roomSpecialTypes.addUndefined(item);
}
+
}
}
@@ -2900,6 +2955,25 @@ public class Room implements Comparable, ISerialize, Runnable {
return habbos;
}
+ public THashSet getHabbosAndBotsAt(short x, short y) {
+ return this.getHabbosAndBotsAt(this.layout.getTile(x, y));
+ }
+
+ public THashSet getHabbosAndBotsAt(RoomTile tile) {
+ THashSet list = new THashSet<>();
+
+ for (Bot bot : this.getBotsAt(tile)) {
+ list.add(bot.getRoomUnit());
+ }
+
+ for(Habbo habbo : this.getHabbosAt(tile))
+ {
+ list.add(habbo.getRoomUnit());
+ }
+
+ return list;
+ }
+
public THashSet getHabbosOnItem(HabboItem item) {
THashSet habbos = new THashSet<>();
for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) {
@@ -2938,7 +3012,7 @@ public class Room implements Comparable, ISerialize, Runnable {
this.teleportRoomUnitToLocation(roomUnit, x, y, 0.0);
}
- void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y, double z) {
+ public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y, double z) {
if (this.loaded) {
RoomTile tile = this.layout.getTile(x, y);
@@ -3045,7 +3119,7 @@ public class Room implements Comparable, ISerialize, Runnable {
}
}
habbo.getHabboStats().lastChat = millis;
- if (roomChatMessage != null && roomChatMessage.getMessage().equalsIgnoreCase("i am a pirate")) {
+ if (roomChatMessage != null && Emulator.getConfig().getBoolean("easter_eggs.enabled") && roomChatMessage.getMessage().equalsIgnoreCase("i am a pirate")) {
habbo.getHabboStats().chatCounter.addAndGet(1);
Emulator.getThreading().run(new YouAreAPirate(habbo, this));
return;
@@ -3065,9 +3139,11 @@ public class Room implements Comparable, ISerialize, Runnable {
if (roomChatMessage == null || roomChatMessage.getMessage() == null || roomChatMessage.getMessage().equals(""))
return;
- for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) {
- if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentLocation())) {
- return;
+ if(!habbo.hasPermission(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) {
+ for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) {
+ if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentLocation())) {
+ return;
+ }
}
}
@@ -3130,7 +3206,7 @@ public class Room implements Comparable, ISerialize, Runnable {
ServerMessage prefixMessage = null;
if (Emulator.getPluginManager().isRegistered(UsernameTalkEvent.class, true)) {
- UsernameTalkEvent usernameTalkEvent = (UsernameTalkEvent) Emulator.getPluginManager().fireEvent(new UsernameTalkEvent(habbo, roomChatMessage, chatType));
+ UsernameTalkEvent usernameTalkEvent = Emulator.getPluginManager().fireEvent(new UsernameTalkEvent(habbo, roomChatMessage, chatType));
if (usernameTalkEvent.hasCustomComposer()) {
prefixMessage = usernameTalkEvent.getCustomComposer();
}
@@ -3141,7 +3217,7 @@ public class Room implements Comparable, ISerialize, Runnable {
}
ServerMessage clearPrefixMessage = prefixMessage != null ? new RoomUserNameChangedComposer(habbo).compose() : null;
- Rectangle show = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation());
+ Rectangle tentRectangle = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation());
String trimmedMessage = roomChatMessage.getMessage().replaceAll("\\s+$","");
@@ -3187,7 +3263,7 @@ public class Room implements Comparable, ISerialize, Runnable {
if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance ||
h.equals(habbo) ||
this.hasRights(h) ||
- noChatLimit) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
+ noChatLimit) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) {
if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) {
if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage);
@@ -3197,13 +3273,19 @@ public class Room implements Comparable, ISerialize, Runnable {
h.getClient().sendResponse(clearPrefixMessage);
}
}
+ continue;
}
+ // Staff should be able to see the tent chat anyhow
+ showTentChatMessageOutsideTentIfPermitted(h, roomChatMessage, tentRectangle);
}
} else if (chatType == RoomChatType.SHOUT) {
ServerMessage message = new RoomUserShoutComposer(roomChatMessage).compose();
for (Habbo h : this.getHabbos()) {
- if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (show == null || RoomLayout.tileInSquare(show, h.getRoomUnit().getCurrentLocation()))) {
+ // Show the message
+ // If the receiving Habbo has not ignored the sending Habbo
+ // AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo
+ if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) {
if (prefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(prefixMessage);
}
@@ -3211,7 +3293,10 @@ public class Room implements Comparable, ISerialize, Runnable {
if (clearPrefixMessage != null && !h.getHabboStats().preferOldChat) {
h.getClient().sendResponse(clearPrefixMessage);
}
+ continue;
}
+ // Staff should be able to see the tent chat anyhow, even when not in the same tent
+ showTentChatMessageOutsideTentIfPermitted(h, roomChatMessage, tentRectangle);
}
}
@@ -3244,10 +3329,18 @@ public class Room implements Comparable, ISerialize, Runnable {
RoomChatMessage itemMessage = new RoomChatMessage(Emulator.getTexts().getValue(item.getBaseItem().getName() + ".message." + randomValue, item.getBaseItem().getName() + ".message." + randomValue + " not found!"), habbo, RoomChatMessageBubbles.getBubble(Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.bubble", RoomChatMessageBubbles.PARROT.getType())));
- this.sendComposer(new RoomUserShoutComposer(itemMessage).compose());
+ this.sendComposer(new RoomUserTalkComposer(itemMessage).compose());
try {
item.onClick(habbo.getClient(), this, new Object[0]);
+ item.setExtradata("1");
+ updateItemState(item);
+
+ Emulator.getThreading().run(() -> {
+ item.setExtradata("0");
+ updateItemState(item);
+ }, 2000);
+
break;
} catch (Exception e) {
LOGGER.error("Caught exception", e);
@@ -3255,11 +3348,25 @@ public class Room implements Comparable, ISerialize, Runnable {
}
}
}
-
}
}
}
+ /**
+ * Sends the given message to the receiving Habbo if the Habbo has the ACC_SEE_TENTCHAT permission and is not within the tent
+ * @param receivingHabbo The receiving Habbo
+ * @param roomChatMessage The message to receive
+ * @param tentRectangle The whole tent area from where the sending Habbo is saying something
+ */
+ private void showTentChatMessageOutsideTentIfPermitted(Habbo receivingHabbo, RoomChatMessage roomChatMessage, Rectangle tentRectangle) {
+ if (receivingHabbo != null && receivingHabbo.hasPermission(Permission.ACC_SEE_TENTCHAT) && tentRectangle != null && !RoomLayout.tileInSquare(tentRectangle, receivingHabbo.getRoomUnit().getCurrentLocation())) {
+ RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage);
+ staffChatMessage.setMessage("[" + Emulator.getTexts().getValue("hotel.room.tent.prefix") + "] " + staffChatMessage.getMessage());
+ final ServerMessage staffMessage = new RoomUserWhisperComposer(staffChatMessage).compose();
+ receivingHabbo.getClient().sendResponse(staffMessage);
+ }
+ }
+
public THashSet getLockedTiles() {
THashSet lockedTiles = new THashSet<>();
@@ -3336,9 +3443,9 @@ public class Room implements Comparable, ISerialize, Runnable {
return items;
if (this.loaded) {
- if (this.tileCache.containsKey(tile)) {
- return this.tileCache.get(tile);
- }
+ THashSet cachedItems = this.tileCache.get(tile);
+ if(cachedItems != null)
+ return cachedItems;
}
TIntObjectIterator iterator = this.roomItems.iterator();
@@ -3444,6 +3551,27 @@ public class Room implements Comparable, ISerialize, Runnable {
return highestItem;
}
+ public HabboItem getTopItemAt(THashSet tiles, HabboItem exclude) {
+ HabboItem highestItem = null;
+ for(RoomTile tile : tiles) {
+
+ if (tile == null)
+ continue;
+
+ for (HabboItem item : this.getItemsAt(tile.x, tile.y)) {
+ if (exclude != null && exclude == item)
+ continue;
+
+ if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item))
+ continue;
+
+ highestItem = item;
+ }
+ }
+
+ return highestItem;
+ }
+
public double getTopHeightAt(int x, int y) {
HabboItem item = this.getTopItemAt(x, y);
@@ -3486,10 +3614,37 @@ public class Room implements Comparable, ISerialize, Runnable {
return lowestChair;
}
+ public HabboItem getTallestChair(RoomTile tile) {
+ HabboItem lowestChair = null;
+
+ THashSet items = this.getItemsAt(tile);
+ if (items != null && !items.isEmpty()) {
+ for (HabboItem item : items) {
+
+ if(!item.getBaseItem().allowSit())
+ continue;
+
+ if(lowestChair != null && lowestChair.getZ() + Item.getCurrentHeight(lowestChair) > item.getZ() + Item.getCurrentHeight(item))
+ continue;
+
+ lowestChair = item;
+ }
+ }
+
+ return lowestChair;
+ }
+
public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) {
if (x < 0 || y < 0 || this.layout == null)
return calculateHeightmap ? Short.MAX_VALUE : 0.0;
+
+ if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) {
+ FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this));
+ if(event.hasPluginHelper()) {
+ return calculateHeightmap ? event.getHeight() * 256.0D : event.getHeight();
+ }
+ }
double height = this.layout.getHeightAtSquare(x, y);
boolean canStack = true;
@@ -3506,14 +3661,14 @@ public class Room implements Comparable