diff --git a/README.md b/README.md index cf501d89..17618274 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ When making an bug report or a feature request use the template we provide so th - Harmonic - Beny - Claudio +- Alejandro +- Harmony ## Discord ## Join us on Discord at https://discord.gg/BzfFsTp diff --git a/sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql b/sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql new file mode 100644 index 00000000..96f8f5b9 --- /dev/null +++ b/sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql @@ -0,0 +1,31 @@ +#DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 + +INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('commands.plugins.oldstyle', '0'); + +ALTER TABLE `emulator_errors` +ADD COLUMN `version` varchar(64) NOT NULL AFTER `timestamp`, +ADD COLUMN `build_hash` varchar(64) NOT NULL AFTER `version`; + +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('scripter.modtool.tickets', '1'); + +ALTER TABLE `items_crackable` +ADD COLUMN `subscription_duration` int(3) NULL AFTER `required_effect`, +ADD COLUMN `subscription_type` varchar(255) NULL COMMENT 'hc for Habbo Club, bc for Builders Club' AFTER `subscription_duration`; + +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('invisible.prevent.chat', '0'); +INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('invisible.prevent.chat.error', 'While being invisible you cannot talk.'); + +INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('commands.succes.cmd_invisible.updated.back', 'You are now visible again.'); + +INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('commands.error.cmd_mimic.forbidden_clothing', 'The other user has clothing that you do not own yet.'); +ALTER TABLE `permissions` +ADD COLUMN `acc_mimic_unredeemed` enum('0','1') NOT NULL DEFAULT '0'; + +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.max.allowed.items', '100'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.batch.size', '6'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.batch.free.items', '1'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.bonus.min.discounts', '1'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.additional.thresholds', '40;99'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('clothing.strip_unowned', '0'); + +#END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql new file mode 100644 index 00000000..363a6993 --- /dev/null +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -0,0 +1,74 @@ +#DATABASE UPDATE: 2.0.0 -> DEV + +ALTER TABLE `guilds_forums` RENAME TO `old_guilds_forums`; +ALTER TABLE `guilds_forums_comments` RENAME TO `old_guilds_forums_comments`; + +DROP TABLE IF EXISTS `guilds_forums_comments`; +CREATE TABLE `guilds_forums_comments` ( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `thread_id` int(11) NOT NULL DEFAULT 0, + `user_id` int(11) NOT NULL DEFAULT 0, + `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, + `created_at` int(11) NOT NULL DEFAULT 0, + `state` int(11) NOT NULL DEFAULT 0, + `admin_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact; + +CREATE TABLE `guilds_forums_threads` ( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `guild_id` int(11) NULL DEFAULT 0, + `opener_id` int(11) NULL DEFAULT 0, + `subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT '', + `posts_count` int(11) NULL DEFAULT 0, + `created_at` int(11) NULL DEFAULT 0, + `updated_at` int(11) NULL DEFAULT 0, + `state` int(11) NULL DEFAULT 0, + `pinned` tinyint(4) NULL DEFAULT 0, + `locked` tinyint(4) NULL DEFAULT 0, + `admin_id` int(11) NULL DEFAULT 0, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact; + + +DROP PROCEDURE IF EXISTS MIGRATION_FORUMS; +DELIMITER ;; + +CREATE PROCEDURE MIGRATION_FORUMS() +BEGIN + DECLARE n INT DEFAULT 0; + DECLARE i INT DEFAULT 0; + SELECT COUNT(*) FROM `old_guilds_forums` INTO n; + SET i=0; + WHILE i DEV \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index d185e644..177be9a6 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -21,11 +21,16 @@ import com.eu.habbo.threading.runnables.CameraClientAutoReconnect; import com.eu.habbo.util.imager.badges.BadgeImager; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; import java.io.InputStreamReader; +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.zip.Checksum; public final class Emulator { @@ -39,21 +44,18 @@ public final class Emulator public final static int BUILD = 0; - public static final String version = "Version: " + MAJOR + "." + MINOR + "." + BUILD; + public final static String PREVIEW = "RC-3"; + public static final String version = "Arcturus Morningstar"+ " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW; - public static MessengerBuddy publicChatBuddy; - + public static String build = ""; public static boolean isReady = false; - public static boolean isShuttingDown = false; - public static boolean stopped = false; - public static boolean debugging = false; private static int timeStarted = 0; @@ -89,12 +91,15 @@ public final class Emulator { try { + Locale.setDefault(new Locale("en")); + + setBuild(); Emulator.stopped = false; ConsoleCommand.load(); Emulator.logging = new Logging(); - Emulator.getLogging().logStart("\r" + Emulator.logo); + Emulator.getLogging().logStart("\r" + Emulator.logo + + " Build: " + build + "\n"); random = new Random(); - publicChatBuddy = new MessengerBuddy(-1, "Staff Chat", "", (short) 0, 0); long startTime = System.nanoTime(); Emulator.runtime = Runtime.getRuntime(); @@ -159,9 +164,9 @@ public final class Emulator @Override public void run() { - Emulator.getLogging().logStart("Arcturus Morningstar does not include a camera by default, if you wish to have that feature please download the PNGCamera plugin!"); - Emulator.getLogging().logStart("This is not an official arcturus build. This is a community forked version released under the GPL License. You are breaking no laws by using this software... Except for copyright infringement from sulake i suppose... oopsie."); - Emulator.getLogging().logStart("- Krews.org Team"); + Emulator.getLogging().logStart("Thankyou for downloading Arcturus Morningstar! This is a Release Candidate for 2.0.0, if you find any bugs please place them on our git repository."); + Emulator.getLogging().logStart("Please note, Arcturus Emulator is a project by TheGeneral, we take no credit for the original work, and only the work we have continued. If you'd like to support the project, join our discord at: "); + Emulator.getLogging().logStart("https://discord.gg/syuqgN"); System.out.println("Waiting for commands: "); } }, 3500); @@ -193,6 +198,38 @@ public final class Emulator } } + private static void setBuild() { + if(Emulator.class.getProtectionDomain().getCodeSource() == null) { + build = "UNKNOWN"; + return; + } + + StringBuilder sb = new StringBuilder(); + try + { + String filepath = new File(Emulator.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath(); + MessageDigest md = MessageDigest.getInstance("MD5");// MD5 + FileInputStream fis = new FileInputStream(filepath); + byte[] dataBytes = new byte[1024]; + int nread = 0; + + while((nread = fis.read(dataBytes)) != -1) + md.update(dataBytes, 0, nread); + + byte[] mdbytes = md.digest(); + + for(int i=0; i REMOVE_INACTIVE_GUILDS) { Emulator.getGameEnvironment().getGuildManager().clearInactiveGuilds(); - Emulator.getGameEnvironment().getGuildForumManager().clearInactiveForums(); + ForumThread.clearCache(); LAST_INACTIVE_GUILDS_CLEARED = time; } diff --git a/src/main/java/com/eu/habbo/core/ErrorLog.java b/src/main/java/com/eu/habbo/core/ErrorLog.java index a9bf00ee..4afcf4b7 100644 --- a/src/main/java/com/eu/habbo/core/ErrorLog.java +++ b/src/main/java/com/eu/habbo/core/ErrorLog.java @@ -11,13 +11,20 @@ import java.sql.SQLException; public class ErrorLog implements Loggable { - public final static String insertQuery = "INSERT INTO emulator_errors (timestamp, type, stacktrace) VALUES (?, ?, ?)"; + public final static String insertQuery = "INSERT INTO emulator_errors (timestamp, version, build_hash, type, stacktrace) VALUES (?, ?, ?, ?, ?)"; + public final String version; + public final String buildHash; + public final int timeStamp; public final String type; public final String stackTrace; public ErrorLog(String type, Throwable e) { + + this.version = Emulator.version; + this.buildHash = Emulator.version; + this.timeStamp = Emulator.getIntUnixTimestamp(); this.type = type; @@ -38,6 +45,9 @@ public class ErrorLog implements Loggable public ErrorLog(String type, String message) { + this.version = Emulator.version; + this.buildHash = Emulator.build; + this.timeStamp = Emulator.getIntUnixTimestamp(); this.type = type; this.stackTrace = message; @@ -47,8 +57,10 @@ public class ErrorLog implements Loggable public void log(PreparedStatement statement) throws SQLException { statement.setInt(1, this.timeStamp); - statement.setString(2, this.type); - statement.setString(3, this.stackTrace); + statement.setString(2, this.version); + statement.setString(3, this.buildHash); + statement.setString(4, this.type); + statement.setString(5, this.stackTrace); statement.addBatch(); } } diff --git a/src/main/java/com/eu/habbo/core/consolecommands/ConsoleInfoCommand.java b/src/main/java/com/eu/habbo/core/consolecommands/ConsoleInfoCommand.java index 806b95d5..7c08d398 100644 --- a/src/main/java/com/eu/habbo/core/consolecommands/ConsoleInfoCommand.java +++ b/src/main/java/com/eu/habbo/core/consolecommands/ConsoleInfoCommand.java @@ -22,6 +22,10 @@ public class ConsoleInfoCommand extends ConsoleCommand long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60); System.out.println("Emulator version: " + Emulator.version); + System.out.println("Emulator build: " + Emulator.build); + + System.out.println(""); + System.out.println("Hotel Statistics"); System.out.println("- Users: " + Emulator.getGameEnvironment().getHabboManager().getOnlineCount()); System.out.println("- Rooms: " + Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size()); diff --git a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java index af05965b..09d5aec1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java +++ b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java @@ -11,7 +11,6 @@ import com.eu.habbo.habbohotel.commands.CommandHandler; import com.eu.habbo.habbohotel.crafting.CraftingManager; import com.eu.habbo.habbohotel.guides.GuideManager; import com.eu.habbo.habbohotel.guilds.GuildManager; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumManager; import com.eu.habbo.habbohotel.hotelview.HotelViewManager; import com.eu.habbo.habbohotel.items.ItemManager; import com.eu.habbo.habbohotel.modtool.ModToolManager; @@ -28,7 +27,6 @@ public class GameEnvironment private HabboManager habboManager; private NavigatorManager navigatorManager; private GuildManager guildManager; - private GuildForumManager guildForumManager; private ItemManager itemManager; private CatalogManager catalogManager; private HotelViewManager hotelViewManager; @@ -60,7 +58,6 @@ public class GameEnvironment this.botManager = new BotManager(); this.petManager = new PetManager(); this.guildManager = new GuildManager(); - this.guildForumManager = new GuildForumManager(); this.catalogManager = new CatalogManager(); this.roomManager = new RoomManager(); this.navigatorManager = new NavigatorManager(); @@ -74,6 +71,7 @@ public class GameEnvironment this.pollManager = new PollManager(); this.roomManager.loadPublicRooms(); + this.navigatorManager.loadNavigator(); this.creditsScheduler = new CreditsScheduler(); Emulator.getThreading().run(this.creditsScheduler); @@ -116,11 +114,6 @@ public class GameEnvironment return this.guildManager; } - public GuildForumManager getGuildForumManager() - { - return this.guildForumManager; - } - public ItemManager getItemManager() { return this.itemManager; diff --git a/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java b/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java index 0a65a8ac..4b9e8868 100644 --- a/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java @@ -295,6 +295,8 @@ public class AchievementManager } } + habbo.getClient().sendResponse(new AddHabboItemComposer(badge.getId(), AddHabboItemComposer.AddHabboItemCategory.BADGE)); + habbo.getHabboStats().addAchievementScore(newLevel.points); if (newLevel.rewardAmount > 0) 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 e762df0e..f1208640 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java @@ -144,11 +144,8 @@ public class BotManager roomUnit.setRotation(RoomUserRotation.SOUTH); roomUnit.setLocation(location); HabboItem topItem = room.getTopItemAt(location.x, location.y); - - if (topItem != null ) - roomUnit.setZ(topItem.getBaseItem().allowSit() ? topItem.getZ() : topItem.getZ() + Item.getCurrentHeight(topItem)); - - roomUnit.setPreviousLocationZ(roomUnit.getZ()); + roomUnit.setZ(roomUnit.getCurrentLocation().getStackHeight()); + roomUnit.setPreviousLocationZ(roomUnit.getCurrentLocation().getStackHeight()); roomUnit.setPathFinderRoom(room); roomUnit.setRoomUnitType(RoomUnitType.BOT); roomUnit.setCanWalk(room.isAllowBotsWalk()); @@ -164,6 +161,7 @@ public class BotManager if (topItem != null) { + roomUnit.setZ(topItem.getBaseItem().allowSit() ? topItem.getZ() : topItem.getZ() + Item.getCurrentHeight(topItem)); try { topItem.onWalkOn(bot.getRoomUnit(), room, null); 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 d3cf80b9..a3da7344 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -99,20 +99,28 @@ public class ButlerBot extends Bot b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername())); } }); + List failedReached = new ArrayList(); failedReached.add(new Runnable() { public void run() { - if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance")) { + if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) { for (Runnable t : tasks) { t.run(); } } } }); + Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), tasks, failedReached)); + + if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) > 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 { diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java index 5cdec1da..37a7e473 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java @@ -21,7 +21,13 @@ public class CatalogLimitedConfiguration implements Runnable this.itemId = itemId; this.totalSet = totalSet; this.limitedNumbers = availableNumbers; - Collections.shuffle(this.limitedNumbers); + + if(Emulator.getConfig().getBoolean("catalog.ltd.random", true)) { + Collections.shuffle(this.limitedNumbers); + } + else { + Collections.reverse(this.limitedNumbers); + } } public int getNumber() @@ -80,7 +86,13 @@ public class CatalogLimitedConfiguration implements Runnable } this.totalSet += amount; - Collections.shuffle(this.limitedNumbers); + + if(Emulator.getConfig().getBoolean("catalog.ltd.random", true)) { + Collections.shuffle(this.limitedNumbers); + } + else { + Collections.reverse(this.limitedNumbers); + } } } 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 1997b0dc..edaedd7e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -5,10 +5,12 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.catalog.layouts.*; import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.SoundTrack; import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; @@ -39,6 +41,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.*; import java.util.*; +import java.util.stream.Collectors; public class CatalogManager { @@ -1043,16 +1046,13 @@ public class CatalogManager } } - int totalCredits = 0; - int totalPoints = 0; - THashSet itemsList = new THashSet<>(); if (amount > 1 && !CatalogItem.haveOffer(item)) { String message = Emulator.getTexts().getValue("scripter.warning.catalog.amount").replace("%username%", habbo.getHabboInfo().getUsername()).replace("%itemname%", item.getName()).replace("%pagename%", page.getCaption()); - Emulator.getGameEnvironment().getModToolManager().quickTicket(habbo.getClient().getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(habbo.getClient(), message); Emulator.getLogging().logUserLine(message); habbo.getClient().sendResponse(new AlertPurchaseUnavailableComposer(AlertPurchaseUnavailableComposer.ILLEGAL)); return; @@ -1071,205 +1071,171 @@ public class CatalogManager limitedStack = limitedConfiguration.getTotalSet(); } + int totalCredits = free ? 0 : this.calculateDiscountedPrice(item.getCredits(), amount, item); + int totalPoints = free ? 0 : this.calculateDiscountedPrice(item.getPoints(), amount, item); + + if (totalCredits > 0 && habbo.getHabboInfo().getCredits() - totalCredits < 0) return; + if (totalPoints > 0 && habbo.getHabboInfo().getCurrencyAmount(item.getPointsType()) - totalPoints < 0) return; + List badges = new ArrayList<>(); + Map> unseenItems = new HashMap<>(); boolean badgeFound = false; - for (int i = 0; i < amount; i++) - { - if (free || (item.getCredits() <= habbo.getClient().getHabbo().getHabboInfo().getCredits() - totalCredits)) - { - if (free || - item.getPoints() <= habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()) - totalPoints) - { - if (((i + 1) % 6 != 0 && CatalogItem.haveOffer(item)) || !CatalogItem.haveOffer(item)) - { - totalCredits += item.getCredits(); - totalPoints += item.getPoints(); - } - habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp()); + for (int i = 0; i < amount; i++) { + habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp()); - //for (int j = 0; j < item.getAmount(); j++) - //{ - for (Item baseItem : item.getBaseItems()) - { - for (int k = 0; k < item.getItemAmount(baseItem.getId()); k++) - { - if (baseItem.getName().startsWith("rentable_bot_") || baseItem.getName().startsWith("bot_")) - { - String type = item.getName().replace("rentable_bot_", ""); - type = type.replace("bot_", ""); - type = type.replace("visitor_logger", "visitor_log"); + for (Item baseItem : item.getBaseItems()) { + for (int k = 0; k < item.getItemAmount(baseItem.getId()); k++) { + if (baseItem.getName().startsWith("rentable_bot_") || baseItem.getName().startsWith("bot_")) { + String type = item.getName().replace("rentable_bot_", ""); + type = type.replace("bot_", ""); + type = type.replace("visitor_logger", "visitor_log"); - THashMap data = new THashMap<>(); + THashMap data = new THashMap<>(); - for (String s : item.getExtradata().split(";")) - { - if (s.contains(":")) - { - data.put(s.split(":")[0], s.split(":")[1]); - } - } - - Bot bot = Emulator.getGameEnvironment().getBotManager().createBot(data, type); - - if (bot != null) - { - bot.setOwnerId(habbo.getClient().getHabbo().getHabboInfo().getId()); - bot.setOwnerName(habbo.getClient().getHabbo().getHabboInfo().getUsername()); - bot.needsUpdate(true); - Emulator.getThreading().run(bot); - habbo.getClient().getHabbo().getInventory().getBotsComponent().addBot(bot); - habbo.getClient().sendResponse(new AddBotComposer(bot)); - } else - { - throw new Exception("Failed to create bot of type: " + type); - } - } else if (baseItem.getType() == FurnitureType.EFFECT) - { - int effectId = baseItem.getEffectM(); - - if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) - { - effectId = baseItem.getEffectF(); - } - - if (effectId > 0) - { - habbo.getInventory().getEffectsComponent().createEffect(effectId); - } - } else if (Item.isPet(baseItem)) - { - String[] data = extradata.split("\n"); - - if (data.length < 3) - { - habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); - return; - } - - Pet pet = null; - try - { - pet = Emulator.getGameEnvironment().getPetManager().createPet(baseItem, data[0], data[1], data[2], habbo.getClient()); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); - } - - if (pet == null) - { - habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); - return; - } - - habbo.getClient().getHabbo().getInventory().getPetsComponent().addPet(pet); - habbo.getClient().sendResponse(new AddPetComposer(pet)); - habbo.getClient().sendResponse(new PetBoughtNotificationComposer(pet, false)); - - AchievementManager.progressAchievement(habbo.getClient().getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLover")); - } else if (baseItem.getType() == FurnitureType.BADGE) - { - if (!habbo.getInventory().getBadgesComponent().hasBadge(baseItem.getName())) - { - if (!badges.contains(baseItem.getName())) - { - badges.add(baseItem.getName()); - } - } else - { - badgeFound = true; - } - } else - { - if (baseItem.getInteractionType().getType() == InteractionTrophy.class || baseItem.getInteractionType().getType() == InteractionBadgeDisplay.class) - { - if (baseItem.getInteractionType().getType() == InteractionBadgeDisplay.class && !habbo.getClient().getHabbo().getInventory().getBadgesComponent().hasBadge(extradata)) - { - Emulator.getGameEnvironment().getModToolManager().quickTicket(habbo.getClient().getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.catalog.badge_display").replace("%username%", habbo.getClient().getHabbo().getHabboInfo().getUsername()).replace("%badge%", extradata)); - extradata = "UMAD"; - } - - extradata = habbo.getClient().getHabbo().getHabboInfo().getUsername() + (char) 9 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "-" + Calendar.getInstance().get(Calendar.YEAR) + (char) 9 + Emulator.getGameEnvironment().getWordFilter().filter(extradata.replace(((char)9) + "", ""), habbo); - } - - if (InteractionTeleport.class.isAssignableFrom(baseItem.getInteractionType().getType())) - { - HabboItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - HabboItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - Emulator.getGameEnvironment().getItemManager().insertTeleportPair(teleportOne.getId(), teleportTwo.getId()); - itemsList.add(teleportOne); - itemsList.add(teleportTwo); - } else if (baseItem.getInteractionType().getType() == InteractionHopper.class) - { - HabboItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - - Emulator.getGameEnvironment().getItemManager().insertHopper(hopper); - - itemsList.add(hopper); - } else if (baseItem.getInteractionType().getType() == InteractionGuildFurni.class || baseItem.getInteractionType().getType() == InteractionGuildGate.class) - { - int guildId; - try - { - guildId = Integer.parseInt(extradata); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); - return; - } - - InteractionGuildFurni habboItem = (InteractionGuildFurni) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - habboItem.setExtradata(""); - habboItem.needsUpdate(true); - - Emulator.getThreading().run(habboItem); - Emulator.getGameEnvironment().getGuildManager().setGuild(habboItem, guildId); - itemsList.add(habboItem); - - if(baseItem.getName().equals("guild_forum")) { - Emulator.getGameEnvironment().getGuildManager().getGuild(guildId).setForum(true); - Emulator.getGameEnvironment().getGuildManager().getGuild(guildId).needsUpdate = true; - Emulator.getGameEnvironment().getGuildForumManager().addGuildForum(guildId); - { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET forum = '1' WHERE id = ?")) - - { - statement.setInt(1, guildId); - statement.execute(); - } - } - - } - - } - else if (baseItem.getInteractionType().getType() == InteractionMusicDisc.class) - { - SoundTrack track = Emulator.getGameEnvironment().getItemManager().getSoundTrack(item.getExtradata()); - - if (track == null) - { - habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); - return; - } - - InteractionMusicDisc habboItem = (InteractionMusicDisc) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, habbo.getClient().getHabbo().getHabboInfo().getUsername() + "\n" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "\n" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "\n" + Calendar.getInstance().get(Calendar.YEAR) + "\n" + track.getLength() + "\n" + track.getName() + "\n" + track.getId()); - habboItem.needsUpdate(true); - - Emulator.getThreading().run(habboItem); - itemsList.add(habboItem); - - AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MusicCollector")); - } else - { - HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - itemsList.add(habboItem); - } + for (String s : item.getExtradata().split(";")) { + if (s.contains(":")) { + data.put(s.split(":")[0], s.split(":")[1]); } } + + Bot bot = Emulator.getGameEnvironment().getBotManager().createBot(data, type); + + if (bot != null) { + bot.setOwnerId(habbo.getClient().getHabbo().getHabboInfo().getId()); + bot.setOwnerName(habbo.getClient().getHabbo().getHabboInfo().getUsername()); + bot.needsUpdate(true); + Emulator.getThreading().run(bot); + habbo.getClient().getHabbo().getInventory().getBotsComponent().addBot(bot); + habbo.getClient().sendResponse(new AddBotComposer(bot)); + + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) { + unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BOT, new ArrayList<>()); + } + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BOT).add(bot.getId()); + } else { + throw new Exception("Failed to create bot of type: " + type); + } + } else if (baseItem.getType() == FurnitureType.EFFECT) { + int effectId = baseItem.getEffectM(); + + if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { + effectId = baseItem.getEffectF(); + } + + if (effectId > 0) { + habbo.getInventory().getEffectsComponent().createEffect(effectId); + } + } else if (Item.isPet(baseItem)) { + String[] data = extradata.split("\n"); + + if (data.length < 3) { + habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); + return; + } + + Pet pet = null; + try { + pet = Emulator.getGameEnvironment().getPetManager().createPet(baseItem, data[0], data[1], data[2], habbo.getClient()); + } catch (Exception e) { + Emulator.getLogging().logErrorLine(e); + habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); + } + + if (pet == null) { + habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); + return; + } + + habbo.getClient().getHabbo().getInventory().getPetsComponent().addPet(pet); + habbo.getClient().sendResponse(new AddPetComposer(pet)); + habbo.getClient().sendResponse(new PetBoughtNotificationComposer(pet, false)); + + AchievementManager.progressAchievement(habbo.getClient().getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLover")); + + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.PET)) { + unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.PET, new ArrayList<>()); + } + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.PET).add(pet.getId()); + } else if (baseItem.getType() == FurnitureType.BADGE) { + if (!habbo.getInventory().getBadgesComponent().hasBadge(baseItem.getName())) { + if (!badges.contains(baseItem.getName())) { + badges.add(baseItem.getName()); + } + } else { + badgeFound = true; + } + } else { + if (baseItem.getInteractionType().getType() == InteractionTrophy.class || baseItem.getInteractionType().getType() == InteractionBadgeDisplay.class) { + if (baseItem.getInteractionType().getType() == InteractionBadgeDisplay.class && !habbo.getClient().getHabbo().getInventory().getBadgesComponent().hasBadge(extradata)) { + ScripterManager.scripterDetected(habbo.getClient(), Emulator.getTexts().getValue("scripter.warning.catalog.badge_display").replace("%username%", habbo.getClient().getHabbo().getHabboInfo().getUsername()).replace("%badge%", extradata)); + extradata = "UMAD"; + } + + extradata = habbo.getClient().getHabbo().getHabboInfo().getUsername() + (char) 9 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "-" + Calendar.getInstance().get(Calendar.YEAR) + (char) 9 + Emulator.getGameEnvironment().getWordFilter().filter(extradata.replace(((char) 9) + "", ""), habbo); + } + + if (InteractionTeleport.class.isAssignableFrom(baseItem.getInteractionType().getType())) { + HabboItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + HabboItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + Emulator.getGameEnvironment().getItemManager().insertTeleportPair(teleportOne.getId(), teleportTwo.getId()); + itemsList.add(teleportOne); + itemsList.add(teleportTwo); + } else if (baseItem.getInteractionType().getType() == InteractionHopper.class) { + HabboItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + + Emulator.getGameEnvironment().getItemManager().insertHopper(hopper); + + itemsList.add(hopper); + } else if (baseItem.getInteractionType().getType() == InteractionGuildFurni.class || baseItem.getInteractionType().getType() == InteractionGuildGate.class) { + int guildId; + try { + guildId = Integer.parseInt(extradata); + } catch (Exception e) { + Emulator.getLogging().logErrorLine(e); + habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); + return; + } + + InteractionGuildFurni habboItem = (InteractionGuildFurni) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + habboItem.setExtradata(""); + habboItem.needsUpdate(true); + + Emulator.getThreading().run(habboItem); + Emulator.getGameEnvironment().getGuildManager().setGuild(habboItem, guildId); + itemsList.add(habboItem); + + if (baseItem.getName().equals("guild_forum")) { + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + if (guild != null) { + guild.setForum(true); + guild.needsUpdate = true; + guild.run(); + } + } + + } else if (baseItem.getInteractionType().getType() == InteractionMusicDisc.class) { + SoundTrack track = Emulator.getGameEnvironment().getItemManager().getSoundTrack(item.getExtradata()); + + if (track == null) { + habbo.getClient().sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); + return; + } + + InteractionMusicDisc habboItem = (InteractionMusicDisc) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, habbo.getClient().getHabbo().getHabboInfo().getUsername() + "\n" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "\n" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "\n" + Calendar.getInstance().get(Calendar.YEAR) + "\n" + track.getLength() + "\n" + track.getName() + "\n" + track.getId()); + habboItem.needsUpdate(true); + + Emulator.getThreading().run(habboItem); + itemsList.add(habboItem); + + AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MusicCollector")); + } else { + HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + itemsList.add(habboItem); + } } - //} } } } @@ -1305,12 +1271,10 @@ public class CatalogManager } } - if (purchasedEvent.itemsList != null) + if (purchasedEvent.itemsList != null && !purchasedEvent.itemsList.isEmpty()) { - habbo.getClient().sendResponse(new AddHabboItemComposer(purchasedEvent.itemsList)); habbo.getClient().getHabbo().getInventory().getItemsComponent().addItems(purchasedEvent.itemsList); - habbo.getClient().sendResponse(new PurchaseOKComposer(purchasedEvent.catalogItem)); - habbo.getClient().sendResponse(new InventoryRefreshComposer()); + unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(HabboItem::getId).collect(Collectors.toList())); Emulator.getPluginManager().fireEvent(new UserCatalogFurnitureBoughtEvent(habbo, item, purchasedEvent.itemsList)); @@ -1323,6 +1287,10 @@ public class CatalogManager } } + if (!purchasedEvent.badges.isEmpty() && !unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BADGE)) { + unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>()); + } + for (String b : purchasedEvent.badges) { HabboBadge badge = new HabboBadge(0, b, 0, habbo); @@ -1334,9 +1302,15 @@ public class CatalogManager keys.put("image", "${image.library.url}album1584/" + badge.getCode() + ".gif"); keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received")); habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys)); + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BADGE).add(badge.getId()); } habbo.getClient().getHabbo().getHabboStats().addPurchase(purchasedEvent.catalogItem); + habbo.getClient().sendResponse(new AddHabboItemComposer(unseenItems)); + + habbo.getClient().sendResponse(new PurchaseOKComposer(purchasedEvent.catalogItem)); + habbo.getClient().sendResponse(new InventoryRefreshComposer()); + } catch (Exception e) { Emulator.getLogging().logPacketError(e); @@ -1398,4 +1372,28 @@ public class CatalogManager { return this.targetOffers.get(offerId); } + + private int calculateDiscountedPrice(int originalPrice, int amount, CatalogItem item) { + if (!CatalogItem.haveOffer(item)) return originalPrice * amount; + + int basicDiscount = amount / DiscountComposer.DISCOUNT_BATCH_SIZE; + + int bonusDiscount = 0; + if (basicDiscount >= DiscountComposer.MINIMUM_DISCOUNTS_FOR_BONUS) { + if (amount % DiscountComposer.DISCOUNT_BATCH_SIZE == DiscountComposer.DISCOUNT_BATCH_SIZE - 1) { + bonusDiscount = 1; + } + + bonusDiscount += basicDiscount - DiscountComposer.MINIMUM_DISCOUNTS_FOR_BONUS; + } + + int additionalDiscounts = 0; + for (int threshold : DiscountComposer.ADDITIONAL_DISCOUNT_THRESHOLDS) { + if (amount >= threshold) additionalDiscounts++; + } + + int totalDiscountedItems = (basicDiscount * DiscountComposer.DISCOUNT_AMOUNT_PER_BATCH) + bonusDiscount + additionalDiscounts; + + return Math.max(0, originalPrice * (amount - totalDiscountedItems)); + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java index a53828a4..92a79c4d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java @@ -132,8 +132,8 @@ public class MarketPlace public static List getOffers(int minPrice, int maxPrice, String search, int sort) { - List offers = new ArrayList(10); - String query = "SELECT B.* FROM marketplace_items a INNER JOIN (SELECT b.item_id AS base_item_id, b.limited_data AS ltd_data, marketplace_items.*, AVG(price) as avg, MIN(marketplace_items.price) as minPrice, MAX(marketplace_items.price) as maxPrice, COUNT(*) as number, (SELECT COUNT(*) FROM marketplace_items c INNER JOIN items as items_b ON c.item_id = items_b.id WHERE state = 2 AND items_b.item_id = base_item_id AND DATE(from_unixtime(sold_timestamp)) = CURDATE()) as sold_count_today FROM marketplace_items INNER JOIN items b ON marketplace_items.item_id = b.id WHERE price = (SELECT MIN(e.price) FROM marketplace_items e, items d WHERE e.item_id = d.id AND d.item_id = b.item_id AND e.state = 1 AND e.timestamp > ? GROUP BY d.item_id) AND state = 1 AND timestamp > ?"; + List offers = new ArrayList<>(10); + String query = "SELECT B.* FROM marketplace_items a INNER JOIN (SELECT b.item_id AS base_item_id, b.limited_data AS ltd_data, marketplace_items.*, AVG(price) as avg, MIN(marketplace_items.price) as minPrice, MAX(marketplace_items.price) as maxPrice, COUNT(*) as number, (SELECT COUNT(*) FROM marketplace_items c INNER JOIN items as items_b ON c.item_id = items_b.id WHERE state = 2 AND items_b.item_id = base_item_id AND DATE(from_unixtime(sold_timestamp)) = CURDATE()) as sold_count_today FROM marketplace_items INNER JOIN items b ON marketplace_items.item_id = b.id INNER JOIN items_base bi ON b.item_id = bi.id WHERE price = (SELECT MIN(e.price) FROM marketplace_items e, items d WHERE e.item_id = d.id AND d.item_id = b.item_id AND e.state = 1 AND e.timestamp > ? GROUP BY d.item_id) AND state = 1 AND timestamp > ?"; if (minPrice > 0) { query += " AND CEIL(price + (price / 100)) >= " + minPrice; @@ -144,7 +144,7 @@ public class MarketPlace } if(search.length() > 0) { - query += " AND items_base.public_name LIKE ?"; + query += " AND bi.public_name LIKE ?"; } query += " GROUP BY base_item_id, ltd_data"; @@ -414,11 +414,14 @@ public class MarketPlace RequestOffersEvent.cachedResults.clear(); try { + client.sendResponse(new RemoveHabboItemComposer(event.item.getGiftAdjustedId())); + client.sendResponse(new InventoryRefreshComposer()); + + event.item.setFromGift(false); + MarketPlaceOffer offer = new MarketPlaceOffer(event.item, event.price, client.getHabbo()); client.getHabbo().getInventory().addMarketplaceOffer(offer); client.getHabbo().getInventory().getItemsComponent().removeHabboItem(event.item); - client.sendResponse(new RemoveHabboItemComposer(event.item.getId())); - client.sendResponse(new InventoryRefreshComposer()); item.setUserId(-1); item.needsUpdate(true); Emulator.getThreading().run(item); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java index 5f6ae287..b7d05c3f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java @@ -54,7 +54,7 @@ public class BadgeCommand extends Command { boolean found; - try (PreparedStatement statement = connection.prepareStatement("SELECT badge_code FROM users_badges INNER JOIN users ON users.id = user_id WHERE users.username = ? AND badge_code = ? LIMIT 1")) + try (PreparedStatement statement = connection.prepareStatement("SELECT `badge_code` FROM `users_badges` INNER JOIN `users` ON `users`.`id` = `user_id` WHERE `users`.`username` = ? AND `badge_code` = ? LIMIT 1")) { statement.setString(1, params[1]); statement.setString(2, params[2]); @@ -71,7 +71,7 @@ public class BadgeCommand extends Command } else { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges VALUES (null, (SELECT id FROM users WHERE username = ? LIMIT 1), 0, ?)")) + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges (`id`, `user_id`, `slot_id`, `badge_code`) VALUES (null, (SELECT `id` FROM `users` WHERE `username` = ? LIMIT 1), 0, ?)")) { statement.setString(1, params[1]); statement.setString(2, params[2]); 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 07b21c88..7a02ae72 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java @@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.permissions.PermissionSetting; import com.eu.habbo.habbohotel.pets.Pet; 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.messages.outgoing.rooms.users.RoomUserTypingComposer; import com.eu.habbo.plugin.events.users.UserCommandEvent; @@ -267,6 +268,13 @@ public class CommandHandler { if (command.key.equalsIgnoreCase(s.toString())) { + if(pet instanceof RideablePet && ((RideablePet)pet).getRider() != null) { + if(((RideablePet) pet).getRider().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) { + ((RideablePet) pet).getRider().getHabboInfo().dismountPet(); + } + break; + } + if (command.level <= pet.getLevel()) pet.handleCommand(command, gameClient.getHabbo(), args); else diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/GiveRankCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/GiveRankCommand.java index 57da48a9..11e3a5c3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/GiveRankCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/GiveRankCommand.java @@ -41,7 +41,7 @@ public class GiveRankCommand extends Command } else { - rank = Emulator.getGameEnvironment().getPermissionsManager().getRank(params[2]); + rank = Emulator.getGameEnvironment().getPermissionsManager().getRankByName(params[2]); } if (rank != null) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java index 464f33b3..876708b5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java @@ -2,8 +2,17 @@ package com.eu.habbo.habbohotel.commands; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; +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.rooms.RoomUserRotation; +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.outgoing.rooms.users.RoomUserRemoveComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; +import com.eu.habbo.threading.runnables.RoomUnitTeleport; public class InvisibleCommand extends Command { @@ -17,10 +26,27 @@ public class InvisibleCommand extends Command { RoomUnit roomUnit = gameClient.getHabbo().getRoomUnit(); + if (roomUnit.isInvisible()) { + RoomLayout roomLayout = roomUnit.getRoom().getLayout(); + + new RoomUnitTeleport(roomUnit, roomUnit.getRoom(), roomLayout.getDoorTile().x, roomLayout.getDoorTile().y, roomLayout.getDoorTile().z, 0).run(); + + roomUnit.setInvisible(false); + roomUnit.setInRoom(true); + + roomUnit.getRoom().sendComposer(new RoomUsersComposer(gameClient.getHabbo()).compose()); + roomUnit.getRoom().sendComposer(new RoomUserStatusComposer(roomUnit).compose()); + + WiredHandler.handle(WiredTriggerType.ENTER_ROOM, roomUnit, roomUnit.getRoom(), null); + roomUnit.getRoom().habboEntered(gameClient.getHabbo()); + + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_invisible.updated.back")); + + return true; + } + roomUnit.setInvisible(true); - gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_invisible.updated")); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserRemoveComposer(roomUnit).compose()); return true; 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 bcf6a56f..dbfa6598 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/MimicCommand.java @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer; import com.eu.habbo.messages.outgoing.users.UserDataComposer; +import com.eu.habbo.util.figure.FigureUtil; public class MimicCommand extends Command { @@ -18,28 +19,24 @@ public class MimicCommand extends Command @Override public boolean handle(GameClient gameClient, String[] params) throws Exception { - if(params.length == 2) - { + if (params.length == 2) { Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); - if (habbo == null) - { + if (habbo == null) { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_mimic.not_found").replace("%user%", ""), RoomChatMessageBubbles.ALERT); return true; } - if(habbo == gameClient.getHabbo()) - { + if (habbo == gameClient.getHabbo()) { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_mimic.not_self"), RoomChatMessageBubbles.ALERT); return true; - } - else if(habbo.hasPermission("acc_not_mimiced") && !gameClient.getHabbo().hasPermission("acc_not_mimiced")) - { + } else if (habbo.hasPermission("acc_not_mimiced") && !gameClient.getHabbo().hasPermission("acc_not_mimiced")) { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_mimic.blocked").replace("%user%", params[1]).replace("%gender_name%", (habbo.getHabboInfo().getGender().equals(HabboGender.M) ? Emulator.getTexts().getValue("gender.him") : Emulator.getTexts().getValue("gender.her"))), RoomChatMessageBubbles.ALERT); return true; - } - else - { + } else if (!habbo.hasPermission("acc_mimic_unredeemed") && FigureUtil.hasBlacklistedClothing(habbo.getHabboInfo().getLook(), gameClient.getHabbo().getForbiddenClothing())) { + 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().setGender(habbo.getHabboInfo().getGender()); gameClient.sendResponse(new UserDataComposer(gameClient.getHabbo())); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/PluginsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/PluginsCommand.java index 26977aa6..cb129f1f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/PluginsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/PluginsCommand.java @@ -2,9 +2,11 @@ package com.eu.habbo.habbohotel.commands; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer; import com.eu.habbo.plugin.HabboPlugin; +import java.util.Collections; + public class PluginsCommand extends Command { public PluginsCommand() @@ -22,7 +24,14 @@ public class PluginsCommand extends Command message.append("\r").append(plugin.configuration.name).append(" By ").append(plugin.configuration.author); } - gameClient.getHabbo().alert(message.toString()); + + if (Emulator.getConfig().getBoolean("commands.plugins.oldstyle")) + { + gameClient.sendResponse(new MessagesForYouComposer(Collections.singletonList(message.toString()))); + } else + { + gameClient.getHabbo().alert(message.toString()); + } return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java index 34ef9372..5f3ffe0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/TestCommand.java @@ -157,7 +157,7 @@ public class TestCommand extends Command ((MonsterplantPet) pet).setPubliclyBreedable(false); ((MonsterplantPet) pet).setCanBreed(true); gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetInformationComposer(pet, gameClient.getHabbo().getHabboInfo().getCurrentRoom()).compose()); + gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetInformationComposer(pet, gameClient.getHabbo().getHabboInfo().getCurrentRoom(), gameClient.getHabbo()).compose()); } } 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 b4286562..4e13453f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/Game.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/Game.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins; @@ -24,28 +25,19 @@ import java.util.Map; public abstract class Game implements Runnable { - public final Class gameTeamClazz; - - - public final Class gamePlayerClazz; + private final Class gameTeamClazz; + private final Class gamePlayerClazz; protected final THashMap teams = new THashMap<>(); - protected final Room room; + private final boolean countsAchievements; - protected final boolean countsAchievements; + private int startTime; - - protected int startTime; - - - protected int pauseTime; - - - protected int endTime; + private int endTime; public boolean isRunning; @@ -132,6 +124,7 @@ public abstract class Game implements Runnable } } + /* boolean deleteGame = true; for (GameTeam team : this.teams.values()) { @@ -146,6 +139,7 @@ public abstract class Game implements Runnable { this.room.deleteGame(this); } + */ } @@ -170,30 +164,7 @@ public abstract class Game implements Runnable } } - - public abstract void run(); - - public void pause() - { - if (this.state.equals(GameState.RUNNING)) - { - this.state = GameState.PAUSED; - this.pauseTime = Emulator.getIntUnixTimestamp(); - } - } - - public void unpause() - { - if (this.state.equals(GameState.PAUSED)) - { - this.state = GameState.RUNNING; - this.endTime = Emulator.getIntUnixTimestamp() + (this.endTime - this.pauseTime); - } - } - - public void stop() - { - this.state = GameState.IDLE; + public void onEnd() { this.endTime = Emulator.getIntUnixTimestamp(); this.saveScores(); @@ -225,18 +196,52 @@ public abstract class Game implements Runnable } } + for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) + { + this.room.updateItem(item); + } + } + + public abstract void run(); + + public void pause() + { + if (this.state.equals(GameState.RUNNING)) + { + this.state = GameState.PAUSED; + } + } + + public void unpause() + { + if (this.state.equals(GameState.PAUSED)) + { + this.state = GameState.RUNNING; + } + } + + public void stop() + { + this.state = GameState.IDLE; + + boolean gamesActive = false; + for(HabboItem timer : room.getFloorItems()) + { + if(timer instanceof InteractionGameTimer) { + if(((InteractionGameTimer) timer).isRunning()) + gamesActive = true; + } + } + + if(gamesActive) { + return; + } + if(Emulator.getPluginManager().isRegistered(GameStoppedEvent.class, true)) { Event gameStoppedEvent = new GameStoppedEvent(this); Emulator.getPluginManager().fireEvent(gameStoppedEvent); } - - WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, this.room, new Object[]{this}); - - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) - { - this.room.updateItem(item); - } } @@ -289,27 +294,33 @@ public abstract class Game implements Runnable } } - public Room getRoom() { return this.room; } - public int getStartTime() { return this.startTime; } - - public int getEndTime() - { - return this.endTime; + public Class getGameTeamClass() { + return gameTeamClazz; } + public Class getGamePlayerClass() { + return gamePlayerClazz; + } - public void addTime(int time) - { - this.endTime += time; + public THashMap getTeams() { + return teams; + } + + public boolean isCountsAchievements() { + return countsAchievements; + } + + public GameState getState() { + return state; } } 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 9cfcfb85..97850d70 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 @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.games.battlebanzai; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.games.*; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTimer; @@ -13,13 +14,17 @@ import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUserAction; import com.eu.habbo.habbohotel.users.Habbo; 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.outgoing.rooms.users.RoomUserActionComposer; import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker; +import gnu.trove.impl.hash.THash; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; -import java.util.Collection; -import java.util.Map; +import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; public class BattleBanzaiGame extends Game { @@ -27,15 +32,15 @@ public class BattleBanzaiGame extends Game public static final int effectId = 33; - public static final int POINTS_HIJACK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.steal"); + public static final int POINTS_HIJACK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.steal", 0); - public static final int POINTS_FILL_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.fill"); + public static final int POINTS_FILL_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.fill", 0); - public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock"); + public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock", 1); - private int timeLeft; + private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Emulator.getConfig().getInt("hotel.banzai.fill.threads", 2)); private int tileCount; @@ -62,22 +67,10 @@ public class BattleBanzaiGame extends Game if(!this.state.equals(GameState.IDLE)) return; - int highestTime = 0; this.countDown = 3; this.resetMap(); - for (Map.Entry set : this.room.getRoomSpecialTypes().getBattleBanzaiTimers().entrySet()) - { - if(set.getValue().getExtradata().isEmpty()) - continue; - - if(highestTime < Integer.valueOf(set.getValue().getExtradata())) - { - highestTime = Integer.valueOf(set.getValue().getExtradata()); - } - } - synchronized (this.teams) { for (GameTeam t : this.teams.values()) @@ -92,13 +85,6 @@ public class BattleBanzaiGame extends Game this.room.updateItemState(item); } - this.timeLeft = highestTime; - - if (this.timeLeft == 0) - { - this.timeLeft = 30; - } - this.start(); } @@ -150,99 +136,50 @@ public class BattleBanzaiGame extends Game } } - if (this.timeLeft > 0) + Emulator.getThreading().run(this, 1000); + + if (this.state.equals(GameState.PAUSED)) return; + + int total = 0; + synchronized (this.lockedTiles) { - Emulator.getThreading().run(this, 1000); - - if (this.state.equals(GameState.PAUSED)) return; - - this.timeLeft--; - - for (Map.Entry set : this.room.getRoomSpecialTypes().getBattleBanzaiTimers().entrySet()) + for (Map.Entry> set : this.lockedTiles.entrySet()) { - set.getValue().setExtradata(this.timeLeft + ""); - this.room.updateItemState(set.getValue()); - } - - int total = 0; - synchronized (this.lockedTiles) - { - for (Map.Entry> set : this.lockedTiles.entrySet()) - { - total += set.getValue().size(); - } - } - - GameTeam highestScore = null; - - synchronized (this.teams) - { - for (Map.Entry set : this.teams.entrySet()) - { - if (highestScore == null || highestScore.getTotalScore() < set.getValue().getTotalScore()) - { - highestScore = set.getValue(); - } - } - } - - if(highestScore != null) - { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) - { - item.setExtradata((highestScore.teamColor.type + 3) + ""); - this.room.updateItemState(item); - } - } - - if(total >= this.tileCount && this.tileCount != 0) - { - this.timeLeft = 0; + total += set.getValue().size(); } } - else + + GameTeam highestScore = null; + + synchronized (this.teams) { - - GameTeam winningTeam = null; - - for (GameTeam team : this.teams.values()) + for (Map.Entry set : this.teams.entrySet()) { - for(GamePlayer player : team.getMembers()) + if (highestScore == null || highestScore.getTotalScore() < set.getValue().getTotalScore()) { - if (player.getScore() > 0) - { - AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer")); - AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallQuestCompleted")); - } - } - - if (winningTeam == null || team.getTotalScore() > winningTeam.getTotalScore()) - { - winningTeam = team; + highestScore = set.getValue(); } } + } - if (winningTeam != null) + if(highestScore != null) + { + for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - for (GamePlayer player : winningTeam.getMembers()) - { - if (player.getScore() > 0) - { - this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose()); - AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner")); - } - } - - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) - { - item.setExtradata((7 + winningTeam.teamColor.type) + ""); - this.room.updateItemState(item); - } - - Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room)); + item.setExtradata((highestScore.teamColor.type + 3) + ""); + this.room.updateItemState(item); } - - this.stop(); + } + + if(total >= this.tileCount && this.tileCount != 0) + { + for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) + { + if(timer.isRunning()) + timer.setRunning(false); + } + + InteractionGameTimer.endGames(room, true); } } catch (Exception e) @@ -251,13 +188,55 @@ public class BattleBanzaiGame extends Game } } + @Override + public void onEnd() { + GameTeam winningTeam = null; + + for (GameTeam team : this.teams.values()) + { + for(GamePlayer player : team.getMembers()) + { + if (player.getScore() > 0) + { + AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer")); + AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallQuestCompleted")); + } + } + + if (winningTeam == null || team.getTotalScore() > winningTeam.getTotalScore()) + { + winningTeam = team; + } + } + + if (winningTeam != null) + { + for (GamePlayer player : winningTeam.getMembers()) + { + if (player.getScore() > 0) + { + this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose()); + AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner")); + } + } + + for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) + { + item.setExtradata((7 + winningTeam.teamColor.type) + ""); + this.room.updateItemState(item); + } + + Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room)); + } + + super.onEnd(); + } + @Override public void stop() { super.stop(); - this.timeLeft = 0; - this.refreshGates(); for (HabboItem tile : this.gameTiles.values()) @@ -265,7 +244,7 @@ public class BattleBanzaiGame extends Game if (tile.getExtradata().equals("1")) { tile.setExtradata("0"); - this.room.updateItemState(tile); + this.room.updateItem(tile); } } this.lockedTiles.clear(); @@ -292,24 +271,13 @@ public class BattleBanzaiGame extends Game } } - public void addPositionToGate(GameTeamColors teamColor) - { - for (InteractionBattleBanzaiGate gate : this.room.getRoomSpecialTypes().getBattleBanzaiGates().values()) - { - if (gate.teamColor != teamColor) - continue; - - if (gate.getExtradata().isEmpty() || gate.getExtradata().equals("0")) - continue; - - gate.setExtradata(Integer.valueOf(gate.getExtradata()) - 1 + ""); - this.room.updateItemState(gate); - break; - } - } - public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo) + { + this.tileLocked(teamColor, item, habbo, false); + } + + public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo, boolean doNotCheckFill) { if(item instanceof InteractionBattleBanzaiTile) { @@ -325,8 +293,102 @@ public class BattleBanzaiGame extends Game { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked")); } + + if (doNotCheckFill) return; + + final int x = item.getX(); + final int y = item.getY(); + + final List> filledAreas = new ArrayList<>(); + final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); + + executor.execute(() -> { + filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x + 1, y, lockedTiles, new ArrayList<>(), teamColor)); + + Optional> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size)); + + if (largestAreaOfAll.isPresent()) + { + for (RoomTile tile: largestAreaOfAll.get()) + { + Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny(); + + tileItem.ifPresent(habboItem -> { + this.tileLocked(teamColor, habboItem, habbo, true); + + habboItem.setExtradata((2 + (teamColor.type * 3) + 3) + ""); + this.room.updateItem(habboItem); + }); + } + + this.refreshCounters(teamColor); + if (habbo != null) + { + habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size()); + } + } + }); } + private List floodFill(int x, int y, THashSet lockedTiles, List stack, GameTeamColors color) + { + if (this.isOutOfBounds(x, y) || this.isForeignLockedTile(x, y, color)) return null; + + RoomTile tile = this.room.getLayout().getTile((short)x, (short)y); + + if (this.hasLockedTileAtCoordinates(x, y, lockedTiles) || stack.contains(tile)) return stack; + + stack.add(tile); + + List> result = new ArrayList<>(); + result.add(this.floodFill(x, y - 1, lockedTiles, stack, color)); + result.add(this.floodFill(x, y + 1, lockedTiles, stack, color)); + result.add(this.floodFill(x - 1, y, lockedTiles, stack, color)); + result.add(this.floodFill(x + 1, y, lockedTiles, stack, color)); + + if (result.contains(null)) return null; + + Optional> biggestArea = result.stream().max(Comparator.comparing(List::size)); + + return biggestArea.orElse(null); + + } + + private boolean hasLockedTileAtCoordinates(int x, int y, THashSet lockedTiles) + { + for (HabboItem item : lockedTiles) + { + if (item.getX() == x && item.getY() == y) return true; + } + + return false; + } + + private boolean isOutOfBounds(int x, int y) + { + for (HabboItem item : this.gameTiles.values()) + { + if (item.getX() == x && item.getY() == y) return false; + } + + return true; + } + + private boolean isForeignLockedTile(int x, int y, GameTeamColors color) + { + for (HashMap.Entry> lockedTilesForColor : this.lockedTiles.entrySet()) { + if (lockedTilesForColor.getKey() == color) continue; + + for (HabboItem item : lockedTilesForColor.getValue()) { + if (item.getX() == x && item.getY() == y) return true; + } + } + + return false; + } public void refreshCounters() { diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java index 55e7f3f2..9894169d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java @@ -4,6 +4,8 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.GameTeamColors; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; +import com.eu.habbo.habbohotel.rooms.Room; public class BattleBanzaiGameTeam extends GameTeam { @@ -24,14 +26,17 @@ public class BattleBanzaiGameTeam extends GameTeam public void removeMember(GamePlayer gamePlayer) { Game game = gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().getGame(gamePlayer.getHabbo().getHabboInfo().getCurrentGame()); - if(game instanceof BattleBanzaiGame) - { - ((BattleBanzaiGame) game).addPositionToGate(gamePlayer.getTeamColor()); - } + Room room = gamePlayer.getHabbo().getRoomUnit().getRoom(); gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gamePlayer.getHabbo(), 0, -1); gamePlayer.getHabbo().getRoomUnit().setCanWalk(true); super.removeMember(gamePlayer); + + if(room != null && room.getRoomSpecialTypes() != null) { + for (InteractionGameGate gate : room.getRoomSpecialTypes().getBattleBanzaiGates().values()) { + gate.updateState(game, 5); + } + } } } 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 24c3b368..616242a2 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 @@ -9,6 +9,7 @@ import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreeze import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTimer; import com.eu.habbo.habbohotel.items.interactions.games.freeze.gates.InteractionFreezeGate; import com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards.InteractionFreezeScoreboard; +import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectTeleport; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; @@ -45,8 +46,6 @@ public class FreezeGame extends Game public static int FREEZE_LOOSE_POINTS; public static boolean POWERUP_STACK; - private int timeLeft; - public FreezeGame(Room room) { super(FreezeGameTeam.class, FreezeGamePlayer.class, room, true); @@ -59,49 +58,13 @@ public class FreezeGame extends Game if(this.state == GameState.RUNNING) return; - int highestTime = 0; - this.resetMap(); - for (Map.Entry set : this.room.getRoomSpecialTypes().getFreezeTimers().entrySet()) - { - if(set.getValue().getExtradata().isEmpty()) - continue; - - if(highestTime < Integer.valueOf(set.getValue().getExtradata())) - { - highestTime = Integer.valueOf(set.getValue().getExtradata()); - } - } - for (GameTeam t : this.teams.values()) { t.initialise(); } - if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) - { - for (Habbo habbo : this.room.getHabbos()) - { - if (this.getTeamForHabbo(habbo) == null) - { - for (HabboItem item : this.room.getItemsAt(habbo.getRoomUnit().getCurrentLocation())) - { - if (item instanceof InteractionFreezeTile) - { - this.room.teleportHabboToItem(habbo, this.room.getRoomSpecialTypes().getRandomFreezeExitTile()); - } - } - } - } - } - this.timeLeft = highestTime; - - if (this.timeLeft == 0) - { - this.timeLeft = 30; - } - this.start(); } @@ -117,22 +80,6 @@ public class FreezeGame extends Game } } - public synchronized void placebackHelmet(GameTeamColors teamColor) - { - for (InteractionFreezeGate gate : this.room.getRoomSpecialTypes().getFreezeGates().values()) - { - if (gate.teamColor != teamColor) - continue; - - if (gate.getExtradata().isEmpty() || gate.getExtradata().equals("0")) - continue; - - gate.setExtradata(Integer.valueOf(gate.getExtradata()) - 1 + ""); - this.room.updateItemState(gate); - break; - } - } - public void throwBall(Habbo habbo, InteractionFreezeTile item) { if (!this.state.equals(GameState.RUNNING) || !habbo.getHabboInfo().isInGame() || habbo.getHabboInfo().getCurrentGame() != this.getClass()) @@ -280,9 +227,26 @@ public class FreezeGame extends Game super.start(); + if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) + { + for (Habbo habbo : this.room.getHabbos()) + { + if (this.getTeamForHabbo(habbo) == null) + { + for (HabboItem item : this.room.getItemsAt(habbo.getRoomUnit().getCurrentLocation())) + { + if (item instanceof InteractionFreezeTile) + { + HabboItem exitTile = this.room.getRoomSpecialTypes().getRandomFreezeExitTile(); + WiredEffectTeleport.teleportUnitToTile(habbo.getRoomUnit(), this.room.getLayout().getTile(exitTile.getX(), exitTile.getY())); + } + } + } + } + } + this.refreshGates(); - WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, null); this.setFreezeTileState("1"); this.run(); } @@ -295,50 +259,36 @@ public class FreezeGame extends Game if (this.state.equals(GameState.IDLE)) return; - if (this.timeLeft > 0) + Emulator.getThreading().run(this, 1000); + + if (this.state.equals(GameState.PAUSED)) return; + + for (GameTeam team : this.teams.values()) { - Emulator.getThreading().run(this, 1000); - - if (this.state.equals(GameState.PAUSED)) return; - - this.timeLeft--; - - for (GameTeam team : this.teams.values()) + for (GamePlayer player : team.getMembers()) { - for (GamePlayer player : team.getMembers()) - { - ((FreezeGamePlayer)player).cycle(); - } - - int totalScore = team.getTotalScore(); - - THashMap scoreBoards = this.room.getRoomSpecialTypes().getFreezeScoreboards(team.teamColor); - - for (InteractionFreezeScoreboard scoreboard : scoreBoards.values()) - { - if(scoreboard.getExtradata().isEmpty()) - { - scoreboard.setExtradata("0"); - } - - int oldScore = Integer.valueOf(scoreboard.getExtradata()); - - if(oldScore == totalScore) - continue; - - scoreboard.setExtradata(totalScore + ""); - this.room.updateItemState(scoreboard); - } + ((FreezeGamePlayer)player).cycle(); } - for (Map.Entry set : this.room.getRoomSpecialTypes().getFreezeTimers().entrySet()) + int totalScore = team.getTotalScore(); + + THashMap scoreBoards = this.room.getRoomSpecialTypes().getFreezeScoreboards(team.teamColor); + + for (InteractionFreezeScoreboard scoreboard : scoreBoards.values()) { - set.getValue().setExtradata(this.timeLeft + ""); - this.room.updateItemState(set.getValue()); + if(scoreboard.getExtradata().isEmpty()) + { + scoreboard.setExtradata("0"); + } + + int oldScore = Integer.valueOf(scoreboard.getExtradata()); + + if(oldScore == totalScore) + continue; + + scoreboard.setExtradata(totalScore + ""); + this.room.updateItemState(scoreboard); } - } else - { - this.stop(); } } catch (Exception e) @@ -352,8 +302,6 @@ public class FreezeGame extends Game { super.stop(); - this.timeLeft = 0; - GameTeam winningTeam = null; for(GameTeam team : this.teams.values()) diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java index d92f11b7..49831106 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java @@ -4,6 +4,8 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.GameTeamColors; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; +import com.eu.habbo.habbohotel.rooms.Room; public class FreezeGameTeam extends GameTeam { @@ -16,15 +18,18 @@ public class FreezeGameTeam extends GameTeam public void removeMember(GamePlayer gamePlayer) { Game game = gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); - if(game instanceof FreezeGame) - { - ((FreezeGame) game).placebackHelmet(gamePlayer.getTeamColor()); - } + Room room = gamePlayer.getHabbo().getRoomUnit().getRoom(); gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gamePlayer.getHabbo(), 0, -1); gamePlayer.getHabbo().getRoomUnit().setCanWalk(true); super.removeMember(gamePlayer); + + if(room != null && room.getRoomSpecialTypes() != null) { + for (InteractionGameGate gate : room.getRoomSpecialTypes().getFreezeGates().values()) { + gate.updateState(game, 5); + } + } } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java index 7bd0ba26..602a4571 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java @@ -14,51 +14,19 @@ import java.util.Map; public class WiredGame extends Game { - private int timeLeft = 30; public WiredGame(Room room) { super(GameTeam.class, GamePlayer.class, room , false); } @Override - public void initialise() - { - for (Map.Entry set : this.room.getRoomSpecialTypes().getGameTimers().entrySet()) - { - if(set.getValue().getExtradata().isEmpty()) - continue; + public void initialise() { - if(this.timeLeft < Integer.valueOf(set.getValue().getExtradata())) - { - this.timeLeft = Integer.valueOf(set.getValue().getExtradata()); - } - } - - if (this.timeLeft <= 30) - { - this.timeLeft = 30; - } - - this.run(); } @Override - public void run() - { - if (this.timeLeft > 0) - { - Emulator.getThreading().run(this, 1000); - this.timeLeft--; - for (Map.Entry set : this.room.getRoomSpecialTypes().getGameTimers().entrySet()) - { - set.getValue().setExtradata(this.timeLeft + ""); - this.room.updateItemState(set.getValue()); - } - } - else - { - this.stop(); - } + public void run() { + } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java b/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java index c4997f48..7c47bc3f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java @@ -17,7 +17,7 @@ public class Guild implements Runnable private int roomId; private String roomName; private GuildState state; - private int rights; + private boolean rights; private int colorOne; private int colorTwo; private String badge; @@ -43,7 +43,7 @@ public class Guild implements Runnable this.state = GuildState.values()[set.getInt("state")]; this.roomId = set.getInt("room_id"); this.roomName = set.getString("room_name"); - this.rights = set.getString("rights").equalsIgnoreCase("1") ? 1 : 0; + this.rights = set.getString("rights").equalsIgnoreCase("1"); this.colorOne = set.getInt("color_one"); this.colorTwo = set.getInt("color_two"); this.badge = set.getString("badge"); @@ -67,7 +67,7 @@ public class Guild implements Runnable this.name = name; this.description = description; this.state = GuildState.OPEN; - this.rights = 0; + this.rights = false; this.colorOne = colorOne; this.colorTwo = colorTwo; this.badge = badge; @@ -114,12 +114,12 @@ public class Guild implements Runnable { if(this.needsUpdate) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET name = ?, description = ?, state = ?, rights = ?, color_one = ?, color_two = ?, badge = ?, read_forum = ?, post_messages = ?, post_threads = ?, mod_forum = ? WHERE id = ?")) + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds SET name = ?, description = ?, state = ?, rights = ?, color_one = ?, color_two = ?, badge = ?, read_forum = ?, post_messages = ?, post_threads = ?, mod_forum = ?, forum = ? WHERE id = ?")) { statement.setString(1, this.name); statement.setString(2, this.description); statement.setInt(3, this.state.state); - statement.setString(4, this.rights == 1 ? "1" : "0"); + statement.setString(4, this.rights ? "1" : "0"); statement.setInt(5, this.colorOne); statement.setInt(6, this.colorTwo); statement.setString(7, this.badge); @@ -127,7 +127,8 @@ public class Guild implements Runnable statement.setString(9, this.postMessages.name()); statement.setString(10, this.postThreads.name()); statement.setString(11, this.modForum.name()); - statement.setInt(12, this.id); + statement.setString(12, this.forum ? "1" : "0"); + statement.setInt(13, this.id); statement.execute(); this.needsUpdate = false; @@ -199,12 +200,12 @@ public class Guild implements Runnable this.state = state; } - public int getRights() + public boolean getRights() { return this.rights; } - public void setRights(int rights) + public void setRights(boolean rights) { this.rights = rights; } diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java index 79df8f7b..8005ebb0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java @@ -23,7 +23,6 @@ public class GuildManager { private final THashMap> guildParts; - private final TIntObjectMap guilds; public GuildManager() { @@ -40,7 +39,7 @@ public class GuildManager { this.guildParts.clear(); for (GuildPartType t : GuildPartType.values()) { - this.guildParts.put(t, new THashMap()); + this.guildParts.put(t, new THashMap<>()); } try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThread.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThread.java new file mode 100644 index 00000000..4b54271a --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThread.java @@ -0,0 +1,478 @@ +package com.eu.habbo.habbohotel.guilds.forums; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.ISerialize; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadBeforeCreated; +import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCreated; +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; +import java.sql.*; +import java.util.*; + +public class ForumThread implements Runnable, ISerialize { + + private final int threadId; + private final int guildId; + private final int openerId; + private final String subject; + private int postsCount; + private final int createdAt; + private int updatedAt; + private ForumThreadState state; + private boolean pinned; + private boolean locked; + private int adminId; + private boolean needsUpdate; + private boolean hasCommentsLoaded; + private final THashMap comments; + private int commentIndex; + private ForumThreadComment lastComment; + + private final static THashMap> guildThreadsCache = new THashMap<>(); + private final static THashMap forumThreadsCache = new THashMap<>(); + + public ForumThread(int threadId, int guildId, int openerId, String subject, int postsCount, int createdAt, int updatedAt, ForumThreadState state, boolean pinned, boolean locked, int adminId, ForumThreadComment lastComment) { + this.threadId = threadId; + this.guildId = guildId; + this.openerId = openerId; + this.subject = subject; + this.postsCount = postsCount; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.state = state; + this.pinned = pinned; + this.locked = locked; + this.adminId = adminId; + this.lastComment = lastComment; + this.comments = new THashMap<>(); + this.needsUpdate = false; + this.hasCommentsLoaded = false; + this.commentIndex = 0; + } + + public ForumThread(ResultSet set) throws SQLException { + this.threadId = set.getInt("id"); + this.guildId = set.getInt("guild_id"); + this.openerId = set.getInt("opener_id"); + this.subject = set.getString("subject"); + this.postsCount = set.getInt("posts_count"); + this.createdAt = set.getInt("created_at"); + this.updatedAt = set.getInt("updated_at"); + this.state = ForumThreadState.fromValue(set.getInt("state")); + this.pinned = set.getInt("pinned") > 0; + this.locked = set.getInt("locked") > 0; + this.adminId = set.getInt("admin_id"); + this.lastComment = null; + + try { + this.lastComment = ForumThreadComment.getById(set.getInt("last_comment_id")); + } + catch (Exception e) { } + + this.comments = new THashMap<>(); + this.needsUpdate = false; + this.hasCommentsLoaded = false; + this.commentIndex = 0; + } + + public int getThreadId() { + return threadId; + } + + public int getGuildId() { + return guildId; + } + + public int getOpenerId() { + return openerId; + } + + public String getSubject() { + return subject; + } + + public int getCreatedAt() { + return createdAt; + } + + public int getPostsCount() { + return postsCount; + } + + public void setPostsCount(int postsCount) { + this.postsCount = postsCount; + this.needsUpdate = true; + } + + public int getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(int updatedAt) { + this.updatedAt = updatedAt; + this.needsUpdate = true; + } + + public ForumThreadState getState() { + return state; + } + + public void setState(ForumThreadState state) { + this.state = state; + this.needsUpdate = true; + } + + public boolean isPinned() { + return pinned; + } + + public void setPinned(boolean pinned) { + this.pinned = pinned; + this.needsUpdate = true; + } + + public boolean isLocked() { + return locked; + } + + public void setLocked(boolean locked) { + this.locked = locked; + this.needsUpdate = true; + } + + public int getAdminId() { + return adminId; + } + + public ForumThreadComment getLastComment() { + return lastComment; + } + + public void setLastComment(ForumThreadComment lastComment) { + this.lastComment = lastComment; + } + + public void setAdminId(int adminId) { + this.adminId = adminId; + this.needsUpdate = true; + } + + private void loadComments() { + if(this.hasCommentsLoaded) + return; + + synchronized (this.comments) { + this.hasCommentsLoaded = true; + + commentIndex = 0; + this.comments.clear(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `thread_id` = ? ORDER BY `id`")) { + statement.setInt(1, this.threadId); + ResultSet set = statement.executeQuery(); + + while (set.next()) { + ForumThreadComment comment = new ForumThreadComment(set); + addComment(comment); + } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + } + + public void addComment(ForumThreadComment comment) { + this.comments.put(comment.getCommentId(), comment); + comment.setIndex(this.commentIndex); + this.commentIndex++; + this.lastComment = comment; + } + + public Collection getComments() { + if(!this.hasCommentsLoaded) { + loadComments(); + } + + return this.comments.values(); + } + + public Collection getComments(int limit, int offset) { + if(!this.hasCommentsLoaded) { + loadComments(); + } + + synchronized (this.comments) { + ArrayList limitedComments = new ArrayList<>(); + + List comments = new ArrayList<>(this.comments.values()); + comments.sort(Comparator.comparingInt(ForumThreadComment::getIndex)); + + Iterator iterator = comments.iterator(); + + for (; offset > 0; --offset) { + if (!iterator.hasNext()) + break; + + iterator.next(); + } + + for (; limit > 0; --limit) { + if (!iterator.hasNext()) + break; + + limitedComments.add(iterator.next()); + } + + return limitedComments; + } + } + + public ForumThreadComment getCommentById(int commentId) { + if(!this.hasCommentsLoaded) { + loadComments(); + } + + synchronized (this.comments) { + return this.comments.get(commentId); + } + } + + @Override + public void serialize(ServerMessage message) { + Habbo opener = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.openerId); + Habbo admin = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.adminId); + + Collection comments = this.getComments(); + int lastSeenAt = 0; + int totalComments = comments.size(); + int newComments = 0; + ForumThreadComment lastComment = this.lastComment; + + if(lastComment == null) { + for (ForumThreadComment comment : comments) { + if (comment.getCreatedAt() > lastSeenAt) { + newComments++; + } + if (lastComment == null || lastComment.getCreatedAt() < comment.getCreatedAt()) { + lastComment = comment; + } + } + this.lastComment = lastComment; + } + + Habbo lastAuthor = lastComment != null ? lastComment.getHabbo() : null; + + int nowTimestamp = Emulator.getIntUnixTimestamp(); + message.appendInt(this.threadId); + message.appendInt(this.openerId); + message.appendString(opener != null ? opener.getHabboInfo().getUsername() : ""); + message.appendString(this.subject); + message.appendBoolean(this.pinned); + message.appendBoolean(this.locked); + message.appendInt(nowTimestamp - this.createdAt); + message.appendInt(totalComments); // total comments + message.appendInt(newComments); // unread comments + message.appendInt(1); + + message.appendInt(lastAuthor != null ? lastAuthor.getHabboInfo().getId() : -1); + message.appendString(lastAuthor != null ? lastAuthor.getHabboInfo().getUsername() : ""); + message.appendInt(nowTimestamp - (lastComment != null ? lastComment.getCreatedAt() : this.updatedAt)); + message.appendByte(this.state.getStateId()); + message.appendInt(this.adminId); + message.appendString(admin != null ? admin.getHabboInfo().getUsername() : ""); + message.appendInt(this.threadId); + } + + @Override + public void run() { + if(!this.needsUpdate) + return; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE `guilds_forums_threads` SET `posts_count` = ?, `updated_at` = ?, `state` = ?, `pinned` = ?, `locked` = ?, `admin_id` = ? WHERE `id` = ?")) + { + statement.setInt(1, this.postsCount); + statement.setInt(2, this.updatedAt); + statement.setInt(3, this.state.getStateId()); + statement.setInt(4, this.pinned ? 1 : 0); + statement.setInt(5, this.locked ? 1 : 0); + statement.setInt(6, this.adminId); + statement.setInt(7, this.threadId); + statement.execute(); + + this.needsUpdate = false; + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + } + + public static ForumThread create(Guild guild, Habbo opener, String subject, String message) throws Exception { + ForumThread createdThread = null; + + if(Emulator.getPluginManager().fireEvent(new GuildForumThreadBeforeCreated(guild, opener, subject, message)).isCancelled()) + return null; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `guilds_forums_threads`(`guild_id`, `opener_id`, `subject`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) + { + int timestamp = Emulator.getIntUnixTimestamp(); + + statement.setInt(1, guild.getId()); + statement.setInt(2, opener.getHabboInfo().getId()); + statement.setString(3, subject); + statement.setInt(4, timestamp); + statement.setInt(5, timestamp); + + if(statement.executeUpdate() < 1) + return null; + + ResultSet set = statement.getGeneratedKeys(); + if(set.next()) { + int threadId = set.getInt(1); + createdThread = new ForumThread(threadId, guild.getId(), opener.getHabboInfo().getId(), subject, 0, timestamp, timestamp, ForumThreadState.OPEN, false, false, 0, null); + cacheThread(createdThread); + + ForumThreadComment comment = ForumThreadComment.create(createdThread, opener, message); + createdThread.addComment(comment); + + Emulator.getPluginManager().fireEvent(new GuildForumThreadCreated(createdThread)); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + return createdThread; + } + + public static THashSet getByGuildId(int guildId) throws SQLException { + THashSet threads = null; + + if(guildThreadsCache.containsKey(guildId)) { + guildThreadsCache.get(guildId); + } + + if(threads != null) + return threads; + + threads = new THashSet(); + + guildThreadsCache.put(guildId, threads); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT A.*, B.`id` AS `last_comment_id` " + + "FROM guilds_forums_threads A " + + "JOIN (" + + "SELECT * " + + "FROM `guilds_forums_comments` " + + "WHERE `id` IN (" + + "SELECT MAX(id) " + + "FROM `guilds_forums_comments` B " + + "GROUP BY `thread_id` " + + "ORDER BY B.`id` ASC " + + ") " + + "ORDER BY `id` DESC " + + ") B ON A.`id` = B.`thread_id` " + + "WHERE A.`guild_id` = ? " + + "ORDER BY A.`pinned` DESC, B.`created_at` DESC " + )) + { + statement.setInt(1, guildId); + ResultSet set = statement.executeQuery(); + + while(set.next()) { + ForumThread thread = new ForumThread(set); + synchronized (threads) { + threads.add(thread); + } + cacheThread(thread); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + return threads; + } + + public static ForumThread getById(int threadId) throws SQLException { + ForumThread foundThread = forumThreadsCache.get(threadId); + + if(foundThread != null) + return foundThread; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement( + "SELECT A.*, B.`id` AS `last_comment_id` " + + "FROM guilds_forums_threads A " + + "JOIN (" + + "SELECT * " + + "FROM `guilds_forums_comments` " + + "WHERE `id` IN (" + + "SELECT MAX(id) " + + "FROM `guilds_forums_comments` B " + + "GROUP BY `thread_id` " + + "ORDER BY B.`id` ASC " + + ") " + + "ORDER BY `id` DESC " + + ") B ON A.`id` = B.`thread_id` " + + "WHERE A.`id` = ? " + + "ORDER BY A.`pinned` DESC, B.`created_at` DESC " + + "LIMIT 1" + )) + { + statement.setInt(1, threadId); + ResultSet set = statement.executeQuery(); + + while(set.next()) { + foundThread = new ForumThread(set); + cacheThread(foundThread); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + return foundThread; + } + + + private static void cacheThread(ForumThread thread) { + synchronized (forumThreadsCache) { + forumThreadsCache.put(thread.threadId, thread); + } + + THashSet guildThreads = guildThreadsCache.get(thread.guildId); + + if(guildThreads == null) { + guildThreads = new THashSet<>(); + synchronized (forumThreadsCache) { + guildThreadsCache.put(thread.guildId, guildThreads); + } + } + + synchronized (guildThreads) { + guildThreads.add(thread); + } + } + + public static void clearCache() { + for(THashSet threads : guildThreadsCache.values()) { + for(ForumThread thread : threads) { + thread.run(); + } + } + + synchronized (forumThreadsCache) { + forumThreadsCache.clear(); + } + + synchronized (guildThreadsCache) { + guildThreadsCache.clear(); + } + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java new file mode 100644 index 00000000..4db3e0fa --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java @@ -0,0 +1,214 @@ +package com.eu.habbo.habbohotel.guilds.forums; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.messages.ISerialize; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCommentBeforeCreated; +import com.eu.habbo.plugin.events.guilds.forums.GuildForumThreadCommentCreated; +import gnu.trove.map.hash.THashMap; + +import java.sql.*; + +public class ForumThreadComment implements Runnable, ISerialize { + + private final int commentId; + private final int threadId; + private final int userId; + private final String message; + private final int createdAt; + private ForumThreadState state; + private int adminId; + private int index; + private boolean needsUpdate; + private static THashMap forumCommentsCache = new THashMap<>(); + + public ForumThreadComment(int commentId, int threadId, int userId, String message, int createdAt, ForumThreadState state, int adminId) { + this.commentId = commentId; + this.threadId = threadId; + this.userId = userId; + this.message = message; + this.createdAt = createdAt; + this.state = state; + this.adminId = adminId; + this.index = -1; + this.needsUpdate = false; + } + + public ForumThreadComment(ResultSet set) throws SQLException { + this.commentId = set.getInt("id"); + this.threadId = set.getInt("thread_id"); + this.userId = set.getInt("user_id"); + this.message = set.getString("message"); + this.createdAt = set.getInt("created_at"); + this.state = ForumThreadState.fromValue(set.getInt("state")); + this.adminId = set.getInt("admin_id"); + this.index = -1; + this.needsUpdate = false; + } + + public static ForumThreadComment getById(int id) { + ForumThreadComment foundComment = forumCommentsCache.get(id); + + if(foundComment != null) + return foundComment; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM `guilds_forums_comments` WHERE `id` = ? LIMIT 1")) + { + statement.setInt(1, id); + ResultSet set = statement.executeQuery(); + + while(set.next()) { + foundComment = new ForumThreadComment(set); + cacheComment(foundComment); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + return foundComment; + } + + public static void cacheComment(ForumThreadComment foundComment) { + forumCommentsCache.put(foundComment.commentId, foundComment); + } + + public static void clearCache() { + forumCommentsCache.clear(); + } + + public int getCommentId() { + return commentId; + } + + public int getThreadId() { + return threadId; + } + + public int getUserId() { + return userId; + } + + public String getMessage() { + return message; + } + + public int getCreatedAt() { + return createdAt; + } + + public ForumThreadState getState() { + return state; + } + + public void setState(ForumThreadState state) { + this.state = state; + this.needsUpdate = true; + } + + public int getAdminId() { + return adminId; + } + + public void setAdminId(int adminId) { + this.adminId = adminId; + this.needsUpdate = true; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public Habbo getHabbo() { + return Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId); + } + + public ForumThread getThread() { + try { + return ForumThread.getById(this.threadId); + } catch (SQLException e) { + return null; + } + } + + @Override + public void serialize(ServerMessage message) { + + HabboInfo habbo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(this.userId); + HabboInfo admin = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(this.adminId); + + message.appendInt(this.commentId); + message.appendInt(this.index); + message.appendInt(this.userId); + message.appendString(habbo != null ? habbo.getUsername() : ""); + message.appendString(habbo != null ? habbo.getLook() : ""); + message.appendInt(Emulator.getIntUnixTimestamp() - this.createdAt); + message.appendString(this.message); + message.appendByte(this.state.getStateId()); + message.appendInt(this.adminId); + message.appendString(admin != null ? admin.getUsername() : ""); + message.appendInt(0); // admin action time ago? + message.appendInt(habbo != null ? habbo.getHabboStats().forumPostsCount : 0); + } + + @Override + public void run() { + if(!this.needsUpdate) + return; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums_comments` SET `state` = ?, `admin_id` = ? WHERE `id` = ?;")) + { + statement.setInt(1, this.state.getStateId()); + statement.setInt(2, this.adminId); + statement.setInt(3, this.commentId); + statement.execute(); + + this.needsUpdate = false; + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + } + + public static ForumThreadComment create(ForumThread thread, Habbo poster, String message) throws Exception { + ForumThreadComment createdComment = null; + + if(Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentBeforeCreated(thread, poster, message)).isCancelled()) + return null; + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO `guilds_forums_comments`(`thread_id`, `user_id`, `message`, `created_at`) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) + { + int timestamp = Emulator.getIntUnixTimestamp(); + + statement.setInt(1, thread.getThreadId()); + statement.setInt(2, poster.getHabboInfo().getId()); + statement.setString(3, message); + statement.setInt(4, timestamp); + + if(statement.executeUpdate() < 1) + return null; + + ResultSet set = statement.getGeneratedKeys(); + if(set.next()) { + int commentId = set.getInt(1); + createdComment = new ForumThreadComment(commentId, thread.getThreadId(), poster.getHabboInfo().getId(), message, timestamp, ForumThreadState.OPEN, 0); + + Emulator.getPluginManager().fireEvent(new GuildForumThreadCommentCreated(createdComment)); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + return createdComment; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadState.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadState.java new file mode 100644 index 00000000..fcd4adf2 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadState.java @@ -0,0 +1,33 @@ +package com.eu.habbo.habbohotel.guilds.forums; + +public enum ForumThreadState { + OPEN(0), + CLOSED(1), + HIDDEN_BY_ADMIN(10), + HIDDEN_BY_STAFF(20); + + private int stateId; + + public int getStateId() + { + return this.stateId; + } + + ForumThreadState(int stateId) + { + this.stateId = stateId; + } + + public static ForumThreadState fromValue(int value) + { + for (ForumThreadState state : ForumThreadState.values()) + { + if (state.stateId == value) + { + return state; + } + } + + return CLOSED; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForum.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForum.java deleted file mode 100644 index 52fdf5af..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForum.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.eu.habbo.habbohotel.guilds.forums; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.ISerialize; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.procedure.TObjectProcedure; - -import java.sql.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -public class GuildForum implements ISerialize { - private final int guild; - - private int totalThreads; - private final TIntObjectHashMap threads; - private int lastRequested = Emulator.getIntUnixTimestamp(); - - public GuildForum(int guild) { - this.guild = guild; - - this.threads = new TIntObjectHashMap(); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT author.username as author_name, author.look as look, COALESCE(admin.username, '') as admin_name, guilds_forums.id as thread_id, 0 as row_number, guilds_forums.* FROM guilds_forums " + - "INNER JOIN users AS author ON author.id = user_id " + - "LEFT JOIN users AS admin ON guilds_forums.admin_id = admin.id " + - "WHERE guild_id = ?")) { - statement.setInt(1, this.guild); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - this.threads.put(set.getInt("id"), new GuildForumThread(set)); - } - } - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - } - - public GuildForumComment getLastComment() { - if (!this.threads.valueCollection().isEmpty()) { - GuildForumThread thread = Collections.max(this.threads.valueCollection(), Comparator.comparing(GuildForumThread::getLastCommentTimestamp)); - - if (thread != null && thread.comments.size() > 0) { - return thread.comments.get(thread.comments.size() - 1); - } - } - - return null; - } - - public List getThreads() { - return new ArrayList<>(this.threads.valueCollection()); - } - - public List getThreadsByAuthor(int userId) { - return this.threads.valueCollection().stream().filter(p -> p.getAuthorId() == userId).collect(Collectors.toList()); - } - - public GuildForumThread getThread(int threadId) { - return threads.get(threadId); - } - - public GuildForumThread createThread(Habbo habbo, String subject, String message) { - int timestamp = Emulator.getIntUnixTimestamp(); - GuildForumThread thread = null; - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO guilds_forums (guild_id, user_id, subject, message, timestamp) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { - statement.setInt(1, this.guild); - statement.setInt(2, habbo.getClient().getHabbo().getHabboInfo().getId()); - statement.setString(3, subject); - statement.setString(4, message); - statement.setInt(5, timestamp); - statement.execute(); - - try (ResultSet set = statement.getGeneratedKeys()) { - if (set.next()) { - thread = new GuildForumThread(habbo, set.getInt(1), this.guild, subject, message, timestamp); - this.threads.put(set.getInt(1), //Thread id - thread); - } - } - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - - return thread; - } - - //TODO: - - - public void hideThread(int threadId) { - this.threads.get(threadId).setState(ThreadState.HIDDEN_BY_ADMIN); - } - - public int getGuild() { - return this.guild; - } - - int getLastRequestedTime() { - return this.lastRequested; - } - - @Override - public void serialize(ServerMessage message) { - - } - - public void serializeThreads(final ServerMessage message) { - synchronized (this.threads) { - message.appendInt(this.threads.size()); - - this.threads.forEachValue(new TObjectProcedure() { - @Override - public boolean execute(GuildForumThread thread) { - thread.serialize(message); - return true; - } - }); - } - } - - public int threadSize() { - synchronized (this.threads) { - return this.threads.size(); - } - } - - void updateLastRequested() { - this.lastRequested = Emulator.getIntUnixTimestamp(); - } - - public enum ThreadState { - CLOSED(0), - OPEN(1), - HIDDEN_BY_ADMIN(10), //DELETED - HIDDEN_BY_STAFF(20); - - public final int state; - - ThreadState(int state) { - this.state = state; - } - - public static ThreadState fromValue(int state) { - switch (state) { - case 0: - return CLOSED; - case 1: - return OPEN; - case 10: - return HIDDEN_BY_ADMIN; - case 20: - return HIDDEN_BY_STAFF; - } - - return OPEN; - } - } - - public void serializeUserForum(ServerMessage response, Habbo habbo) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guild); - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(this.guild); - - Integer amountOfComments = forum.getThreads().stream().map(GuildForumThread::getAmountOfComments).mapToInt(Integer::intValue).sum(); - - response.appendInt(guild.getId()); - - response.appendString(guild.getName()); - response.appendString(guild.getDescription()); - response.appendString(guild.getBadge()); - - response.appendInt(0); - response.appendInt(0); //Rating - response.appendInt(amountOfComments); - - response.appendInt(0); //New Messages - - GuildForumComment comment = this.getLastComment(); - - if (comment != null) { - response.appendInt(comment.getThreadId()); - response.appendInt(comment.getUserId()); - response.appendString(comment.getUserName()); - response.appendInt(Emulator.getIntUnixTimestamp() - comment.getTimestamp()); - - return; - } - - response.appendInt(-1); - response.appendInt(-1); - response.appendString(""); - response.appendInt(0); - } -} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumComment.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumComment.java deleted file mode 100644 index faf2614b..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumComment.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.eu.habbo.habbohotel.guilds.forums; - -import com.eu.habbo.Emulator; -import com.eu.habbo.messages.ISerialize; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; - -public class GuildForumComment implements ISerialize, Runnable { - private int id; - private final int guildId; - private final int threadId; - private int index = -1; - private final int userId; - private final String userName; - private final String look; - private final int timestamp; - private final String message; - private GuildForum.ThreadState state = GuildForum.ThreadState.OPEN; - private int adminId; - private String adminName; - - public GuildForumComment(int guildId, int threadId, int userId, String userName, String look, String message) { - this.guildId = guildId; - this.threadId = threadId; - this.userId = userId; - this.userName = userName; - this.look = look; - this.timestamp = Emulator.getIntUnixTimestamp(); - this.message = message; - this.adminName = ""; - } - - public GuildForumComment(final ResultSet set, int index, int guildId) throws SQLException { - this.id = set.getInt("id"); - this.guildId = guildId; - this.threadId = set.getInt("thread_id"); - this.index = index; - this.userId = set.getInt("user_id"); - this.userName = set.getString("author_name"); - this.look = set.getString("look"); - this.timestamp = set.getInt("timestamp"); - this.message = set.getString("message"); - this.state = GuildForum.ThreadState.valueOf(set.getString("state")); - this.adminId = set.getInt("admin_id"); - this.adminName = set.getString("admin_name"); - } - - public int getAuthorPostCount() { - GuildForum guildForum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(this.guildId); - - List matchingObjects = guildForum.getThreads().stream().flatMap(e -> e.getAllComments().stream()).collect(Collectors.toList()).stream().filter(c -> c.getUserId() == this.userId).collect(Collectors.toList()); - - return matchingObjects.size(); - } - - @Override - public void serialize(ServerMessage message) { - message.appendInt(this.id); - message.appendInt(this.index - 1); - message.appendInt(this.userId); - message.appendString(this.userName); - message.appendString(this.look); - message.appendInt(Emulator.getIntUnixTimestamp() - this.timestamp); - message.appendString(this.message); - message.appendByte(this.state.state); - message.appendInt(this.adminId); - message.appendString(this.adminName); - message.appendInt(0); - message.appendInt(this.getAuthorPostCount()); - } - - public int getId() { - return this.id; - } - - public void setId(int id) { - this.id = id; - } - - public int getThreadId() { - return this.threadId; - } - - public int getIndex() { - return this.index; - } - - public void setIndex(int index) { - this.index = index; - } - - public int getUserId() { - return this.userId; - } - - public String getUserName() { - return this.userName; - } - - public String getLook() { - return this.look; - } - - public int getTimestamp() { - return this.timestamp; - } - - public String getMessage() { - return this.message; - } - - public GuildForum.ThreadState getState() { - return this.state; - } - - public void setState(GuildForum.ThreadState state) { - this.state = state; - } - - public int getAdminId() { - return this.adminId; - } - - public void setAdminId(int adminId) { - this.adminId = adminId; - } - - public String getAdminName() { - return this.adminName; - } - - public void setAdminName(String adminName) { - this.adminName = adminName; - } - - @Override - public void run() { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums_comments SET state = ?, admin_id = ? WHERE id = ?")) { - statement.setString(1, this.state.name()); - statement.setInt(2, this.adminId); - statement.setInt(3, this.getId()); - statement.execute(); - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - } - - public int getGuildId() { - return this.guildId; - } -} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumManager.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumManager.java deleted file mode 100644 index 9cece19c..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumManager.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.eu.habbo.habbohotel.guilds.forums; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.users.Habbo; -import gnu.trove.TCollections; -import gnu.trove.iterator.TIntObjectIterator; -import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.hash.TIntObjectHashMap; - -import java.util.*; - -public class GuildForumManager { - private final TIntObjectMap guildForums; - - public void addGuildForum(int guildId) { - GuildForum forum = new GuildForum(guildId); - - this.guildForums.put(guildId, forum); - } - - public GuildForumManager() { - this.guildForums = TCollections.synchronizedMap(new TIntObjectHashMap()); - } - - public GuildForum getGuildForum(int guildId) { - synchronized (this.guildForums) { - GuildForum forum = this.guildForums.get(guildId); - - if (forum == null) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - - if (guild != null && guild.hasForum()) { - - forum = new GuildForum(guildId); - - this.guildForums.put(guildId, forum); - } - } - - if (forum != null) { - - forum.updateLastRequested(); - - return forum; - } - - return null; - } - } - - public void clearInactiveForums() { - List toRemove = new ArrayList(); - TIntObjectIterator guildForums = this.guildForums.iterator(); - for (int i = this.guildForums.size(); i-- > 0; ) { - try { - guildForums.advance(); - } catch (NoSuchElementException | ConcurrentModificationException e) { - break; - } - - if (guildForums.value().getLastRequestedTime() < Emulator.getIntUnixTimestamp() - 300) { - toRemove.add(guildForums.key()); - } - - for (Integer j : toRemove) { - this.guildForums.remove(j); - } - } - } - - public List getGuildForums(Habbo habbo) { - List forums = new ArrayList<>(); - - for (Integer i : habbo.getHabboStats().guilds) { - forums.add(this.getGuildForum(i)); - } - - return forums; - } - - public List getAllForums() { - List forums = new ArrayList<>(); - - for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getAllGuilds()) { - if (guild != null && guild.hasForum()) { - forums.add(this.getGuildForum(guild.getId())); - } - } - - return forums; - } - - public List getAllForumsWithPosts() { - List forums = new ArrayList<>(); - - for (Guild guild : Emulator.getGameEnvironment().getGuildManager().getAllGuilds()) { - if (guild != null && guild.hasForum()) { - GuildForum forum = this.getGuildForum(guild.getId()); - - if (forum.getLastComment() == null) - continue; - - forums.add(forum); - } - } - - return forums; - } - - private static final Comparator SORT_ACTIVE = new Comparator() { - @Override - public int compare(GuildForum o1, GuildForum o2) { - - if (o2.getLastComment() == null || o2.getLastComment().getTimestamp() <= 0) - return 0; - - if (o1.getLastComment() == null || o1.getLastComment().getTimestamp() <= 0) - return 0; - - return o2.getLastComment().getTimestamp() - o1.getLastComment().getTimestamp(); - } - }; - - private static final Comparator SORT_VISITED = new Comparator() { - @Override - public int compare(GuildForum o1, GuildForum o2) { - - if (o2.getLastRequestedTime() <= 0 || o1.getLastRequestedTime() <= 0) - return 0; - - return o2.getLastRequestedTime() - o1.getLastRequestedTime(); - } - }; - - public List getAllForumsByActive() { - List forums = this.getAllForumsWithPosts(); - - forums.sort(SORT_ACTIVE); - - return forums; - } - - public List getAllForumsByVisited() { - List forums = this.getAllForumsWithPosts(); - - forums.sort(SORT_VISITED); - - return forums; - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumState.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumState.java deleted file mode 100644 index 3f5cc5e4..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumState.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.eu.habbo.habbohotel.guilds.forums; - -public enum GuildForumState -{ - OPEN(0), - CLOSED(1), - HIDDEN_BY_ADMIN(10), - HIDDEN_BY_STAFF(20); - - private int state; - public int getState() - { - return this.state; - } - - GuildForumState(int state) - { - this.state = state; - } - - public static GuildForumState fromValue(int value) - { - for (GuildForumState state : GuildForumState.values()) - { - if (state.state == value) - { - return state; - } - } - - return CLOSED; - } -} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumThread.java b/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumThread.java deleted file mode 100644 index 10620cc1..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumThread.java +++ /dev/null @@ -1,312 +0,0 @@ -package com.eu.habbo.habbohotel.guilds.forums; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.ISerialize; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.map.hash.THashMap; - -import java.sql.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class GuildForumThread implements ISerialize, Runnable { - private final int threadId; - private final int guildId; - private final int authorId; - private final String authorName; - private final String subject; - private final String message; - private GuildForum.ThreadState state; - private final int timestamp; - private boolean pinned = false; - private boolean locked = false; - - private int lastAuthorId = 0; - private String lastAuthorName; - - public int getLastCommentTimestamp() { - return this.lastCommentTimestamp; - } - - private int lastCommentTimestamp = 0; - private int adminId; - private String adminName = ""; - - private int commentsIndex = 1; - - - - public final THashMap comments; - - public GuildForumThread(Habbo habbo, int threadId, int guildId, String subject, String message, int timestamp) { - this.threadId = threadId; - this.guildId = guildId; - this.authorId = habbo.getHabboInfo().getId(); - this.authorName = habbo.getHabboInfo().getUsername(); - this.subject = subject; - this.message = message; - this.state = GuildForum.ThreadState.OPEN; - this.timestamp = timestamp; - this.lastAuthorId = this.authorId; - this.lastAuthorName = this.authorName; - this.lastCommentTimestamp = this.timestamp; - - - this.comments = new THashMap<>(); - } - - - public GuildForumThread(ResultSet set) throws SQLException { - this.threadId = set.getInt("id"); - this.guildId = set.getInt("guild_id"); - this.authorId = set.getInt("user_id"); - this.authorName = set.getString("author_name"); - this.subject = set.getString("subject"); - this.message = set.getString("message"); - this.state = GuildForum.ThreadState.valueOf(set.getString("state")); - this.timestamp = set.getInt("timestamp"); - this.pinned = set.getString("pinned").equals("1"); - this.locked = set.getString("locked").equals("1"); - this.adminId = set.getInt("admin_id"); - this.adminName = set.getString("admin_name"); - - - this.lastAuthorId = this.authorId; - this.lastAuthorName = this.authorName; - this.lastCommentTimestamp = this.timestamp; - - this.comments = new THashMap<>(); - this.comments.put(commentsIndex, new GuildForumComment(set, commentsIndex, guildId)); - commentsIndex++; - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT " + - "author.username AS author_name, " + - "COALESCE(admin.username, '') as admin_name, " + - "author.look, " + - "guilds_forums_comments.* " + - "FROM guilds_forums_comments " + - "INNER JOIN users AS author ON guilds_forums_comments.user_id = author.id " + - "LEFT JOIN users AS admin ON guilds_forums_comments.admin_id = admin.id " + - "WHERE thread_id = ? " + - "ORDER BY id ASC")) { - statement.setInt(1, this.threadId); - try (ResultSet commentSet = statement.executeQuery()) { - while (commentSet.next()) { - this.comments.put(commentsIndex, new GuildForumComment(commentSet, commentsIndex, this.guildId)); - commentsIndex++; - } - } - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - } - - public void setPinned(boolean pinned) { - this.pinned = pinned; - } - - public void setLocked(boolean locked) { - this.locked = locked; - } - - public void addComment(GuildForumComment comment) { - synchronized (this.comments) { - comment.setIndex(commentsIndex); - this.comments.put(commentsIndex, comment); - commentsIndex++; - } - - this.lastAuthorId = comment.getUserId(); - this.lastAuthorName = comment.getUserName(); - this.lastCommentTimestamp = comment.getTimestamp(); - } - - public GuildForumComment addComment(Habbo habbo, String message) { - int commentId = -1; - - GuildForumComment comment = new GuildForumComment(this.guildId, this.threadId, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), habbo.getHabboInfo().getLook(), message); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO guilds_forums_comments (thread_id, user_id, timestamp, message) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { - statement.setInt(1, this.threadId); - statement.setInt(2, habbo.getHabboInfo().getId()); - int nowTimestamp = Emulator.getIntUnixTimestamp(); - statement.setInt(3, nowTimestamp); - statement.setString(4, message); - statement.execute(); - try (ResultSet set = statement.getGeneratedKeys()) { - if (set.next()) { - commentId = set.getInt(1); - } - } - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - - if (commentId >= 0) { - comment.setId(commentId); - addComment(comment); - - return comment; - } - - return null; - } - - public GuildForumComment getCommentById(int id) { - synchronized (this.comments) { - for(GuildForumComment comment : this.comments.values()) { - if(comment.getId() == id) { - return comment; - } - } - } - - return null; - } - - public GuildForumComment getCommentByIndex(int id) { - synchronized (this.comments) { - return this.comments.get(id); - } - } - - - /* Original Group Forum Code By Claudio and TheGeneral. - Rewritten because it was terrible. - Credits To Beny. - */ - public List getComments(int page, int limit) { - - List allComments = new ArrayList(this.comments.values()); - - Collections.reverse(allComments); - - List comments = new ArrayList<>(); - - int start = page; - int end = start + limit; - - int i = 0; - synchronized (this.comments) { - for(GuildForumComment comment : allComments) { - if(i >= start && i < end) { - comments.add(comment); - } - i++; - } - } - - return comments; - } - - public Collection getAllComments() { - synchronized (this.comments) { - return this.comments.values(); - } - } - - public Integer getAmountOfComments() { - synchronized (this.comments) { - return this.comments.size(); - } - } - - public int getId() { - return this.threadId; - } - - public int getGuildId() { - return this.guildId; - } - - public int getCommentsSize() { - return this.comments.size(); - } - - public String getSubject() { - return this.subject; - } - - public int getThreadId() { - return this.threadId; - } - - public int getAuthorId() { - return this.authorId; - } - - public String getAuthorName() { - return this.authorName; - } - - public String getMessage() { - return this.message; - } - - public GuildForum.ThreadState getState() { - return this.state; - } - - public void setState(GuildForum.ThreadState state) { - this.state = state; - } - - public void setAdminId(int adminId) { - this.adminId = adminId; - } - - public void setAdminName(String adminName) { - this.adminName = adminName; - } - - - - public boolean isPinned() { - return pinned; - } - - public boolean isLocked() { - return locked; - } - - @Override - public void serialize(ServerMessage message) { - int nowTimestamp = Emulator.getIntUnixTimestamp(); - message.appendInt(this.threadId); - message.appendInt(this.authorId); - message.appendString(this.authorName); - message.appendString(this.subject); - message.appendBoolean(this.pinned); - message.appendBoolean(this.locked); - message.appendInt(nowTimestamp - this.timestamp); - message.appendInt(this.getCommentsSize()); - message.appendInt(0); - message.appendInt(1); - message.appendInt(this.lastAuthorId); - message.appendString(this.lastAuthorName); - message.appendInt(nowTimestamp - this.lastCommentTimestamp); - message.appendByte(this.state.state); - message.appendInt(this.adminId); - message.appendString(this.adminName); - message.appendInt(this.threadId); - } - - - @Override - public void run() { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE guilds_forums SET message = ?, state = ?, pinned = ?, locked = ?, admin_id = ? WHERE id = ?")) { - statement.setString(1, this.message); - statement.setString(2, this.state.name()); - statement.setString(3, this.pinned ? "1" : "0"); - statement.setString(4, this.locked ? "1" : "0"); - statement.setInt(5, this.adminId); - statement.setInt(6, this.getId()); - statement.execute(); - } catch (SQLException e) { - Emulator.getLogging().logSQLException(e); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java b/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java index fe8dfbec..ef8d53b5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java @@ -17,6 +17,8 @@ public class CrackableReward public final String achievementTick; public final String achievementCracked; public final int requiredEffect; + public final int subscriptionDuration; + public final RedeemableSubscriptionType subscriptionType; public CrackableReward(ResultSet set) throws SQLException { @@ -25,10 +27,15 @@ public class CrackableReward this.achievementTick = set.getString("achievement_tick"); this.achievementCracked = set.getString("achievement_cracked"); this.requiredEffect = set.getInt("required_effect"); + this.subscriptionDuration = set.getInt("subscription_duration"); + this.subscriptionType = RedeemableSubscriptionType.fromString(set.getString("subscription_type")); + String[] prizes = set.getString("prizes").split(";"); this.prizes = new HashMap<>(); + if (set.getString("prizes").isEmpty()) return; + this.totalChance = 0; for (String prize : prizes) { @@ -59,6 +66,8 @@ public class CrackableReward public int getRandomReward() { + if (this.prizes.size() == 0) return 0; + int random = Emulator.getRandom().nextInt(this.totalChance); int notFound = 0; 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 405968d5..cfeef773 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -175,6 +175,7 @@ public class ItemManager this.interactionsList.add(new ItemInteraction("timer", InteractionGameTimer.class)); this.interactionsList.add(new ItemInteraction("pressureplate_group", InteractionGroupPressurePlate.class)); this.interactionsList.add(new ItemInteraction("effect_tile_group", InteractionEffectTile.class)); + this.interactionsList.add(new ItemInteraction("crackable_subscription_box", InteractionRedeemableSubscriptionBox.class)); @@ -660,7 +661,7 @@ public class ItemManager public HabboItem handleOpenRecycleBox(Habbo habbo, HabboItem box) { - Emulator.getThreading().run(new QueryDeleteHabboItem(box)); + Emulator.getThreading().run(new QueryDeleteHabboItem(box.getId())); HabboItem item = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items_presents WHERE item_id = ? LIMIT 1")) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java b/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java new file mode 100644 index 00000000..e16cf981 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java @@ -0,0 +1,26 @@ +package com.eu.habbo.habbohotel.items; + +public enum RedeemableSubscriptionType { + HABBO_CLUB("hc"), + BUILDERS_CLUB("bc"); + + public final String subscriptionType; + + RedeemableSubscriptionType(String subscriptionType) + { + this.subscriptionType = subscriptionType; + } + + public static RedeemableSubscriptionType fromString(String subscriptionType) { + if (subscriptionType == null) return null; + + switch (subscriptionType) { + case "hc": + return HABBO_CLUB; + case "bc": + return BUILDERS_CLUB; + } + + return null; + } +} 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 e4598517..5a3c80fe 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 @@ -11,6 +11,8 @@ 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.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.users.UserClubComposer; +import com.eu.habbo.messages.outgoing.users.UserPermissionsComposer; import com.eu.habbo.threading.runnables.CrackableExplode; import com.eu.habbo.util.pathfinding.Rotation; @@ -77,7 +79,7 @@ public class InteractionCrackable extends HabboItem if (this.cracked) return; - if (client.getHabbo().getRoomUnit().getCurrentLocation().distance(room.getLayout().getTile(this.getX(), this.getY())) > 1.5) + if (this.userRequiredToBeAdjacent() && client.getHabbo().getRoomUnit().getCurrentLocation().distance(room.getLayout().getTile(this.getX(), this.getY())) > 1.5) { client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY()))); return; @@ -129,6 +131,24 @@ public class InteractionCrackable extends HabboItem { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement(rewardData.achievementCracked)); } + + if (rewardData.subscriptionType != null && rewardData.subscriptionDuration > 0) { + // 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(); + break; + case BUILDERS_CLUB: + habbo.alert("Builders club has not been implemented yet. Sorry!"); + break; + } + } } } } @@ -167,6 +187,10 @@ public class InteractionCrackable extends HabboItem return false; } + public boolean userRequiredToBeAdjacent() { + return true; + } + public void reset(Room room) { this.cracked = false; 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 bf5f5093..928ca2d9 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 @@ -50,6 +50,23 @@ public class InteractionDefault extends HabboItem return true; } + @Override + 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... + + try { + this.onWalkOff(unit, room, new Object[]{}); // the unit walked off! + } catch (Exception ignored) { + + } + } + } + @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java index b3027e0d..5b3de90a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java @@ -56,7 +56,7 @@ public class InteractionFXBox extends InteractionDefault @Override public void run() { - new QueryDeleteHabboItem(item).run(); + new QueryDeleteHabboItem(item.getId()).run(); room.sendComposer(new RemoveFloorItemComposer(item).compose()); } }, 500); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java index e756285a..81831ad0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java @@ -35,8 +35,8 @@ public class InteractionHabboClubTeleportTile extends InteractionTeleportTile } @Override - protected boolean canUseTeleport(GameClient client, Room room) + public boolean canUseTeleport(GameClient client, Room room) { - return client.getHabbo().getHabboStats().hasActiveClub(); + return super.canUseTeleport(client, room) && client.getHabbo().getHabboStats().hasActiveClub(); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java index ac43d633..8a11945f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java @@ -1,7 +1,9 @@ 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.messages.outgoing.habboway.nux.NuxAlertComposer; import gnu.trove.map.hash.THashMap; import java.sql.ResultSet; @@ -12,7 +14,8 @@ public class InteractionInformationTerminal extends InteractionCustomValues public static final THashMap defaultValues = new THashMap() { { - this.put("internalLink", "http://arcturus.pw");} + this.put("internalLink", "habbopages/chat/commands"); + } }; public InteractionInformationTerminal(ResultSet set, Item baseItem) throws SQLException @@ -26,8 +29,11 @@ public class InteractionInformationTerminal extends InteractionCustomValues } @Override - public void onPickUp(Room room) - { - this.values.clear(); + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + super.onClick(client, room, objects); + + if(this.values.containsKey("internalLink")) { + client.sendResponse(new NuxAlertComposer(this.values.get("internalLink"))); + } } } 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 53c50531..65fed46a 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 @@ -9,6 +9,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer; import com.eu.habbo.messages.outgoing.users.UserDataComposer; +import com.eu.habbo.util.figure.FigureUtil; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNest.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNest.java index 81a7d709..ab7b4e4b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNest.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNest.java @@ -5,6 +5,7 @@ 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.pets.RideablePet; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; @@ -67,27 +68,24 @@ public class InteractionNest extends HabboItem Pet pet = room.getPet(roomUnit); - if(pet != null) - { - if(pet instanceof HorsePet) - { - if(((HorsePet) pet).getRider() != null) - return; - } + if(pet == null) + return; - if(pet.getPetData().haveNest(this)) - { - if (pet.getEnergy() <= 85) - { - pet.setTask(PetTasks.NEST); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, room.getStackHeight(this.getX(), this.getY(), false) + ""); - room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); - } - } - } + if(pet instanceof RideablePet && ((RideablePet) pet).getRider() != null) + return; + + if(!pet.getPetData().haveNest(this)) + return; + + if(pet.getEnergy() > 85) + return; + + pet.setTask(PetTasks.NEST); + pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); + pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); + pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, room.getStackHeight(this.getX(), this.getY(), false) + ""); + room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); } @Override 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 3574e6d9..a1c75eb9 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 @@ -1,5 +1,6 @@ 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; @@ -8,13 +9,17 @@ 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.ItemIntStateComposer; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class InteractionOneWayGate extends HabboItem { - private int roomUnitID = -1; + private boolean walkable = false; + public InteractionOneWayGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -28,13 +33,13 @@ public class InteractionOneWayGate extends HabboItem @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return roomUnit.getId() == this.roomUnitID; + return this.getBaseItem().allowWalk(); } @Override public boolean isWalkable() { - return this.roomUnitID != -1; + return walkable; } @Override @@ -65,14 +70,50 @@ public class InteractionOneWayGate extends HabboItem if (client != null) { - RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation()); - RoomTile gatePosition = room.getLayout().getTile(this.getX(), this.getY()); + RoomTile tileInfront = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation()); + if(tileInfront == null) + return; - if (tile != null && tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) + RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY()); + if(currentLocation == null) + return; + + RoomUnit unit = client.getHabbo().getRoomUnit(); + if(unit == null) + return; + + + if (tileInfront.x == unit.getX() && tileInfront.y == unit.getY()) { - InteractionOneWayGate gate = this; - if (!room.hasHabbosAt(this.getX(), this.getY()) && gate.roomUnitID == -1) + if(!currentLocation.hasUnits()) { + List onSuccess = new ArrayList(); + List onFail = new ArrayList(); + + onSuccess.add(() -> { + unit.setCanLeaveRoomByDoor(false); + walkable = this.getBaseItem().allowWalk(); + 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)); + }); + + onFail.add(() -> { + unit.setCanLeaveRoomByDoor(true); + walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentLocation); + room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose()); + unit.removeOverrideTile(currentLocation); + }); + + walkable = true; + room.updateTile(currentLocation); + unit.addOverrideTile(currentLocation); + unit.setGoalLocation(currentLocation); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); + room.sendComposer(new ItemIntStateComposer(this.getId(), 1).compose()); + + /* room.scheduledTasks.add(new Runnable() { @Override @@ -80,10 +121,10 @@ public class InteractionOneWayGate extends HabboItem { gate.roomUnitID = client.getHabbo().getRoomUnit().getId(); room.updateTile(gatePosition); - room.sendComposer(new ItemIntStateComposer(InteractionOneWayGate.this.getId(), 1).compose()); client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(InteractionOneWayGate.this.getX(), InteractionOneWayGate.this.getY()), InteractionOneWayGate.this.getRotation() + 4)); } }); + */ } } } @@ -92,10 +133,10 @@ public class InteractionOneWayGate extends HabboItem private void refresh(Room room) { this.setExtradata("0"); - this.roomUnitID = -1; room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose()); room.updateTile(room.getLayout().getTile(this.getX(), this.getY())); } + @Override public void onPickUp(Room room) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPetBreedingNest.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPetBreedingNest.java index 2a156dd6..ce8e0ad0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPetBreedingNest.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPetBreedingNest.java @@ -169,7 +169,7 @@ public class InteractionPetBreedingNest extends HabboItem public void breed(Habbo habbo, String name, int petOneId, int petTwoId) { - Emulator.getThreading().run(new QueryDeleteHabboItem(this)); + Emulator.getThreading().run(new QueryDeleteHabboItem(this.getId())); this.setExtradata("2"); habbo.getHabboInfo().getCurrentRoom().updateItem(this); 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 44ece7a9..276fb788 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,6 +8,7 @@ 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 gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; @@ -99,7 +100,17 @@ public class InteractionPressurePlate extends HabboItem { boolean occupied = false; - for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) + if (room == null || room.getLayout() == null || this.getBaseItem() == null) return; + + RoomTile tileAtItem = room.getLayout().getTile(this.getX(), this.getY()); + + if (tileAtItem == null) return; + + THashSet tiles = room.getLayout().getTilesAt(tileAtItem, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); + + if (tiles == null) return; + + for (RoomTile tile : tiles) { boolean hasHabbos = room.hasHabbosAt(tile.x, tile.y); if (!hasHabbos && this.requiresAllTilesOccupied()) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java new file mode 100644 index 00000000..a0f2da01 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java @@ -0,0 +1,27 @@ +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.RedeemableSubscriptionType; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.users.UserClubComposer; +import com.eu.habbo.messages.outgoing.users.UserPermissionsComposer; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class InteractionRedeemableSubscriptionBox extends InteractionCrackable { + public InteractionRedeemableSubscriptionBox(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public InteractionRedeemableSubscriptionBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, userId, item, extradata, limitedStack, limitedSells); + } + + public boolean userRequiredToBeAdjacent() { + return false; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java index 5a82e972..e15bf896 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java @@ -25,7 +25,7 @@ public class InteractionSwitch extends InteractionDefault @Override public boolean canToggle(Habbo habbo, Room room) { - return super.canToggle(habbo, room) || RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); + return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); } @Override @@ -43,6 +43,9 @@ public class InteractionSwitch extends InteractionDefault @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + if(client == null) + return; + if (!this.canToggle(client.getHabbo(), room)) { RoomTile closestTile = null; 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 4f1ebaf8..e2648655 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 @@ -11,25 +11,31 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.ItemIntStateComposer; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import com.eu.habbo.threading.runnables.teleport.TeleportActionOne; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class InteractionTeleport extends HabboItem { private int targetId; private int targetRoomId; - private int roomUnitID = 0; + private int roomUnitID = -1; + private boolean walkable = false; public InteractionTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); + walkable = baseItem.allowWalk(); } public InteractionTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { super(id, userId, item, extradata, limitedStack, limitedSells); + walkable = item.allowWalk(); } @Override @@ -48,9 +54,87 @@ public class InteractionTeleport extends HabboItem } @Override - public boolean isWalkable() - { - return true; + public boolean isWalkable() { + return walkable; + } + + private void tryTeleport(GameClient client, Room room) { + /* + if user is on item, startTeleport + else if user is on infront, set state 1 and walk on item + else move to infront and interact + */ + + Habbo habbo = client.getHabbo(); + + if(habbo == null) + return; + + RoomUnit unit = habbo.getRoomUnit(); + + if(unit == null) + return; + + RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY()); + + if(currentLocation == null) + return; + + RoomTile infrontTile = room.getLayout().getTileInFront(currentLocation, this.getRotation()); + + if(!canUseTeleport(client, room)) + return; + + if(this.roomUnitID == unit.getId() && unit.getCurrentLocation().equals(currentLocation)) { + startTeleport(room, habbo); + } + else if(unit.getCurrentLocation().equals(currentLocation) || unit.getCurrentLocation().equals(infrontTile)) { + // set state 1 and walk on item + this.roomUnitID = unit.getId(); + this.setExtradata("1"); + room.updateItem(this); + unit.setGoalLocation(infrontTile); + + List onSuccess = new ArrayList(); + List onFail = new ArrayList(); + + onSuccess.add(() -> { + walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentLocation); + tryTeleport(client, room); + unit.removeOverrideTile(currentLocation); + unit.setCanLeaveRoomByDoor(true); + }); + + onFail.add(() -> { + walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentLocation); + this.setExtradata("0"); + room.updateItem(this); + this.roomUnitID = -1; + unit.removeOverrideTile(currentLocation); + unit.setCanLeaveRoomByDoor(true); + }); + + walkable = true; + room.updateTile(currentLocation); + unit.addOverrideTile(currentLocation); + unit.setGoalLocation(currentLocation); + unit.setCanLeaveRoomByDoor(false); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); + } + else { + // walk to teleport and interact + List onSuccess = new ArrayList(); + List onFail = new ArrayList(); + + onSuccess.add(() -> { + tryTeleport(client, room); + }); + + unit.setGoalLocation(infrontTile); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, infrontTile, room, onSuccess, onFail)); + } } @Override @@ -60,54 +144,12 @@ public class InteractionTeleport extends HabboItem if(room != null && client != null && objects.length <= 1) { - RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation()); - RoomTile teleportPosition = room.getLayout().getTile(this.getX(), this.getY()); - - if (tile != null && tile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) - { - if (!room.hasHabbosAt(this.getX(), this.getY()) && this.roomUnitID == 0) - { - room.sendComposer(new ItemIntStateComposer(this.getId(), 1).compose()); - room.scheduledTasks.add(() -> { - if (client.getHabbo().getRoomUnit().isTeleporting) return; - this.roomUnitID = client.getHabbo().getRoomUnit().getId(); - room.updateTile(teleportPosition); - client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - }); - } - } - else if (teleportPosition.equals(client.getHabbo().getRoomUnit().getCurrentLocation()) && tile != null && tile.state != RoomTileState.BLOCKED && tile.state != RoomTileState.INVALID) - { - this.startTeleport(room, client.getHabbo()); - } + tryTeleport(client, room); } } @Override - public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception - { - } - - @Override - public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception - { - super.onWalkOn(roomUnit, room, objects); - - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null && habbo.getRoomUnit().getId() == this.roomUnitID) - { - if (habbo.getRoomUnit().getGoal().equals(room.getLayout().getTile(this.getX(), this.getY()))) - { - this.startTeleport(room, habbo); - } - } - } - - @Override - public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception - { - super.onWalkOff(roomUnit, room, objects); + public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { } @Override @@ -131,23 +173,10 @@ public class InteractionTeleport extends HabboItem { this.targetId = 0; this.targetRoomId = 0; + this.roomUnitID = -1; this.setExtradata("0"); } - protected boolean canUseTeleport(GameClient client, Room room) - { - if(!this.getExtradata().equals("0")) - return false; - - if(client.getHabbo().getRoomUnit().isTeleporting) - return false; - - if (client.getHabbo().getRoomUnit().getCurrentLocation().is(this.getX(), this.getY())) - return true; - - return true; - } - public int getTargetId() { return this.targetId; @@ -174,17 +203,32 @@ public class InteractionTeleport extends HabboItem return false; } + public boolean canUseTeleport(GameClient client, Room room) { + + Habbo habbo = client.getHabbo(); + + if(habbo == null) + return false; + + RoomUnit unit = habbo.getRoomUnit(); + + if(unit == null) + return false; + + if(habbo.getHabboInfo().getRiding() != null) + return false; + + return this.roomUnitID == -1 || this.roomUnitID == unit.getId(); + } + public void startTeleport(Room room, Habbo habbo) { - if (this.canUseTeleport(habbo.getClient(), room)) - { - this.roomUnitID = 0; - habbo.getRoomUnit().isTeleporting = true; - //new TeleportInteraction(room, client, this).run(); - this.setExtradata("1"); - room.updateItem(this); - room.scheduledTasks.add(new TeleportActionOne(this, room, habbo.getClient())); - } + if(habbo.getRoomUnit().isTeleporting) + return; + + this.roomUnitID = -1; + habbo.getRoomUnit().isTeleporting = true; + room.scheduledTasks.add(new TeleportActionOne(this, room, habbo.getClient())); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java index 0a1d9299..fa646222 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.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.Habbo; @@ -27,17 +28,27 @@ public class InteractionTeleportTile extends InteractionTeleport return true; } + @Override + public boolean isWalkable() { + return true; + } + @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { if (roomUnit != null) { - if (roomUnit.getGoal().is(this.getX(), this.getY()) && this.canWalkOn(roomUnit, room, objects)) + RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY()); + + if (roomUnit.getGoal().equals(currentLocation) && this.canWalkOn(roomUnit, room, objects)) { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { + if(!canUseTeleport(habbo.getClient(), room)) + return; + if (!habbo.getRoomUnit().isTeleporting) { this.startTeleport(room, habbo); @@ -46,16 +57,4 @@ public class InteractionTeleportTile extends InteractionTeleport } } } - - @Override - protected boolean canUseTeleport(GameClient client, Room room) - { - if(client.getHabbo().getRoomUnit().isTeleporting) - return false; - - if (client.getHabbo().getRoomUnit().getCurrentLocation().is(this.getX(), this.getY())) - return true; - - return true; - } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java index 00f988c4..971e4b61 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java @@ -34,6 +34,8 @@ public class InteractionWater extends InteractionDefault @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + super.onMove(room, oldLocation, newLocation); + this.recalculate(room); } 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 860c8851..d08f47c2 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 @@ -107,7 +107,7 @@ public abstract class InteractionWired extends HabboItem protected long requiredCooldown() { - return 10L; + return 50L; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java index ddca2a55..83f1407b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.games; +import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; @@ -14,11 +15,13 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem public InteractionGameGate(ResultSet set, Item baseItem, GameTeamColors teamColor) throws SQLException { super(set, baseItem, teamColor); + this.setExtradata("0"); } public InteractionGameGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + this.setExtradata("0"); } @Override @@ -41,4 +44,18 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem super.serializeExtradata(serverMessage); } + + public void updateState(Game game, int maxPlayers) { + int memberCount = 0; + + if(game.getTeam(this.teamColor) != null) { + memberCount = game.getTeam(this.teamColor).getMembers().size(); + } + + if(memberCount > maxPlayers) { + memberCount = maxPlayers; + } + this.setExtradata(memberCount + ""); + game.getRoom().updateItem(this); + } } 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 e6dfd61e..6fec1c99 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,8 @@ 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.battlebanzai.BattleBanzaiGame; +import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.permissions.Permission; @@ -11,15 +13,22 @@ 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.messages.ServerMessage; +import java.lang.reflect.InvocationTargetException; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Map; -public abstract class InteractionGameTimer extends HabboItem +public abstract class InteractionGameTimer extends HabboItem implements Runnable { private int baseTime = 0; - private int lastToggle = 0; + private int timeNow = 0; + private boolean isRunning = false; + private boolean isPaused = false; public InteractionGameTimer(ResultSet set, Item baseItem) throws SQLException { @@ -30,6 +39,7 @@ public abstract class InteractionGameTimer extends HabboItem if (data.length >= 2) { this.baseTime = Integer.valueOf(data[1]); + this.timeNow = this.baseTime; } if (data.length >= 1) @@ -43,6 +53,67 @@ public abstract class InteractionGameTimer extends HabboItem super(id, userId, item, extradata, limitedStack, limitedSells); } + @Override + public void run() { + if(this.needsUpdate() || this.needsDelete()) { + super.run(); + } + + if(this.getRoomId() == 0) + return; + + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + + if(room == null || !this.isRunning || this.isPaused) + return; + + if(this.timeNow > 0) { + Emulator.getThreading().run(this, 1000); + this.timeNow--; + room.updateItem(this); + } + else { + this.isRunning = false; + this.isPaused = false; + endGamesIfLastTimer(room); + } + } + + public static void endGamesIfLastTimer(Room room) { + boolean gamesActive = false; + for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) { + if (timer.isRunning()) + gamesActive = true; + } + + if (!gamesActive) { + endGames(room); + } + } + + public static void endGames(Room room) { + endGames(room, false); + } + + public static void endGames(Room room, boolean overrideTriggerWired) { + + boolean triggerWired = false; + + //end existing games + for (Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = InteractionGameTimer.getOrCreateGame(room, gameClass); + if (!game.state.equals(GameState.IDLE)) { + triggerWired = true; + game.onEnd(); + game.stop(); + } + } + + if(triggerWired) { + WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); + } + } + @Override public void onPickUp(Room room) { @@ -52,8 +123,12 @@ public abstract class InteractionGameTimer extends HabboItem @Override public void onPlace(Room room) { - this.baseTime = 30; - this.setExtradata("30"); + if(this.baseTime == 0) { + this.baseTime = 30; + this.timeNow = this.baseTime; + } + + this.setExtradata(this.timeNow + "\t" + this.baseTime); room.updateItem(this); } @@ -61,7 +136,7 @@ public abstract class InteractionGameTimer extends HabboItem public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString("" + timeNow); super.serializeExtradata(serverMessage); } @@ -81,65 +156,123 @@ public abstract class InteractionGameTimer extends HabboItem @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if (client != null) - { - if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))) - return; - } - - if (client == null) - { - int now = Emulator.getIntUnixTimestamp(); - if (now - this.lastToggle < 3) return; - this.lastToggle = now; - } - if(this.getExtradata().isEmpty()) { this.setExtradata("0"); } - Game game = this.getOrCreateGame(room); - - if ((objects.length >= 2 && objects[1] instanceof WiredEffectType)) + // if wired triggered it + if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning) { - if (game == null || !game.isRunning) - startGame(room); - else if (game.isRunning) - stopGame(room); + endGamesIfLastTimer(room); + + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + if(!game.isRunning) { + game.initialise(); + } + } + + timeNow = this.baseTime; + this.isRunning = true; + room.updateItem(this); + WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { }); + + Emulator.getThreading().run(this); } - - if(objects.length >= 1 && objects[0] instanceof Integer && client != null) + else if(client != null) { - int state = (Integer)objects[0]; + if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))) + return; + + int state = 1; + + if(objects.length >= 1 && objects[0] instanceof Integer) { + state = (Integer) objects[0]; + } switch (state) { case 1: - { - this.startGame(room); + if(this.isRunning) { + this.isPaused = !this.isPaused; + + boolean allPaused = this.isPaused; + for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) { + if(!timer.isPaused) + allPaused = false; + } + + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + if(allPaused) { + game.pause(); + } + else { + game.unpause(); + } + } + + if(!this.isPaused) { + this.isRunning = true; + timeNow = this.baseTime; + room.updateItem(this); + Emulator.getThreading().run(this); + } + } + + if(!this.isRunning) { + endGamesIfLastTimer(room); + + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + game.initialise(); + } + + WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { }); + this.isRunning = true; + timeNow = this.baseTime; + room.updateItem(this); + Emulator.getThreading().run(this); + } break; - } case 2: - { - this.increaseTimer(room); - } - break; + if(!this.isRunning) { + this.increaseTimer(room); + return; + } + + if(this.isPaused) { + this.isPaused = false; + this.isRunning = false; + + timeNow = this.baseTime; + room.updateItem(this); + + endGamesIfLastTimer(room); + } + + break; case 3: - { - this.stopGame(room); - } - break; - } - } - else - { - if (game != null && game.state.equals(GameState.IDLE)) - { - this.startGame(room); + this.isPaused = false; + this.isRunning = false; + + timeNow = this.baseTime; + room.updateItem(this); + + boolean gamesActive = false; + for (InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) { + if (timer.isRunning()) + gamesActive = true; + } + + if (!gamesActive) { + endGames(room); + } + break; } } @@ -152,87 +285,29 @@ public abstract class InteractionGameTimer extends HabboItem } - private Game getOrCreateGame(Room room) + public static Game getOrCreateGame(Room room, Class gameClass) { - Game game = (this.getGameType().cast(room.getGame(this.getGameType()))); + Game game = (gameClass.cast(room.getGame(gameClass))); - if (game == null) - { - try - { - game = this.getGameType().getDeclaredConstructor(Room.class).newInstance(room); + if (game == null) { + try { + game = gameClass.getDeclaredConstructor(Room.class).newInstance(room); room.addGame(game); - } - catch (Exception e) - { - + } catch (Exception e) { + Emulator.getLogging().logErrorLine(e); } } return game; } - private void startGame(Room room) - { - this.needsUpdate(true); - try - { - - room.updateItem(this); - - Game game = this.getOrCreateGame(room); - - if (game.state.equals(GameState.IDLE)) - { - this.setExtradata(this.baseTime + ""); - game.initialise(); - } - else if (game.state.equals(GameState.PAUSED)) - { - game.unpause(); - } - else if (game.state.equals(GameState.RUNNING)) - { - game.pause(); - } - - //} - } - catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - } - } - - private void stopGame(Room room) - { - this.setExtradata(this.baseTime + ""); - this.needsUpdate(true); - Game game = this.getOrCreateGame(room); - - if(game != null && game.state != GameState.IDLE) - { - this.setExtradata(this.baseTime + ""); - game.stop(); - stopGame(room); - } - - room.updateItem(this); - } - private void increaseTimer(Room room) { - Game game = this.getOrCreateGame(room); - - if (game == null) return; - if (game.state.equals(GameState.PAUSED)) - { - stopGame(room); + if(this.isRunning) return; - } - if (game.state.equals(GameState.RUNNING)) return; this.needsUpdate(true); + switch(this.baseTime) { case 0: this.baseTime = 30; break; @@ -247,9 +322,9 @@ public abstract class InteractionGameTimer extends HabboItem this.baseTime = 30; } - this.setExtradata(this.baseTime + ""); - + this.timeNow = this.baseTime; room.updateItem(this); + this.needsUpdate(true); } @Override @@ -265,4 +340,20 @@ public abstract class InteractionGameTimer extends HabboItem { return true; } + + public boolean isRunning() { + return isRunning; + } + + public void setRunning(boolean running) { + isRunning = running; + } + + public int getTimeNow() { + return timeNow; + } + + public void setTimeNow(int timeNow) { + this.timeNow = timeNow; + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java index f072a6cf..7ed26f14 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java @@ -140,8 +140,10 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable @Override public boolean validMove(Room room, RoomTile from, RoomTile to) { + if (room == null || from == null || to == null) return false; + HabboItem topItem = room.getTopItemAt(to.x, to.y, this); - return topItem instanceof InteractionBattleBanzaiTile; + return topItem != null && topItem instanceof InteractionBattleBanzaiTile; //return !(!room.getLayout().tileWalkable(to.x, to.y) || (topItem != null && (!topItem.getBaseItem().setAllowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay()))); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java index 95c08794..28637cba 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.games.GameState; import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.GameTeamColors; @@ -9,6 +10,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; +import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; @@ -67,18 +69,11 @@ public class InteractionBattleBanzaiGate extends InteractionGameGate } else { - if(this.getExtradata().isEmpty()) - { - this.setExtradata("0"); - } - - int value = Integer.valueOf(this.getExtradata()) + 1; - - this.setExtradata(value + ""); - room.updateItem(this); game.addHabbo(room.getHabbo(roomUnit), this.teamColor); } + updateState(game, 5); + super.onWalkOn(roomUnit, room, objects); } } 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 b0e6950c..7f24355a 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 @@ -14,7 +14,7 @@ import com.eu.habbo.plugin.EventHandler; import com.eu.habbo.plugin.events.users.UserDisconnectEvent; import com.eu.habbo.plugin.events.users.UserExitRoomEvent; import com.eu.habbo.plugin.events.users.UserSavedLookEvent; -import com.eu.habbo.util.FigureUtil; +import com.eu.habbo.util.figure.FigureUtil; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java index 9d89852c..0b753421 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java @@ -113,7 +113,13 @@ public class InteractionFreezeBlock extends HabboItem if(player == null) return; - int powerUp = Integer.valueOf(this.getExtradata()) / 1000; + int powerUp; + try { + powerUp = Integer.valueOf(this.getExtradata()) / 1000; + } + catch (NumberFormatException e){ + powerUp = 0; + } if(powerUp >= 2 && powerUp <= 7) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java index 0bebee7f..46ffbe68 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java @@ -66,18 +66,11 @@ public class InteractionFreezeGate extends InteractionGameGate } else { - if(this.getExtradata().isEmpty()) - { - this.setExtradata("0"); - } - - int value = Integer.valueOf(this.getExtradata()) + 1; - - this.setExtradata(value + ""); - room.updateItem(this); game.addHabbo(room.getHabbo(roomUnit), this.teamColor); } + updateState(game, 5); + super.onWalkOn(roomUnit, room, objects); } } 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 25377f03..2e977871 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 @@ -24,7 +24,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi private boolean state; private boolean position; - private boolean direction; + private boolean rotation; public WiredConditionNotMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { @@ -52,23 +52,12 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi if(item != null) { - if(this.state) - { - if(item.getExtradata().equals(setting.state)) - return false; - } + 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(this.position) - { - if((setting.x == item.getX() && setting.y == item.getY())) - return false; - } - - if(this.direction) - { - if((setting.rotation == item.getRotation())) - return false; - } + if(stateMatches && positionMatches && directionMatches) + return false; } else { @@ -102,7 +91,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi data.append(item.toString()).append(";"); } - data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0); + data.append(":").append(this.state ? 1 : 0).append(":").append(this.rotation ? 1 : 0).append(":").append(this.position ? 1 : 0); return data.toString(); } @@ -125,7 +114,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } this.state = data[2].equals("1"); - this.direction = data[3].equals("1"); + this.rotation = data[3].equals("1"); this.position = data[4].equals("1"); } @@ -134,7 +123,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi { this.settings.clear(); this.state = false; - this.direction = false; + this.rotation = false; this.position = false; } @@ -161,7 +150,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi message.appendString(""); message.appendInt(4); message.appendInt(this.state ? 1 : 0); - message.appendInt(this.direction ? 1 : 0); + message.appendInt(this.rotation ? 1 : 0); message.appendInt(this.position ? 1 : 0); message.appendInt(10); message.appendInt(0); @@ -179,7 +168,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi packet.readInt(); this.state = packet.readInt() == 1; - this.direction = packet.readInt() == 1; + this.rotation = packet.readInt() == 1; this.position = packet.readInt() == 1; packet.readString(); 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 917dd042..b1b91c61 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 @@ -94,11 +94,8 @@ public class WiredEffectBotTalk extends InteractionWiredEffect } List bots = room.getBots(this.botName); - int now = Emulator.getIntUnixTimestamp(); for(Bot bot : bots) { - if (now - bot.getChatTimestamp() < bot.getChatDelay()) continue; - if(this.mode == 1) bot.shout(message); else 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 29cf36fb..ede7c898 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 @@ -119,21 +119,18 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect this.items.remove(item); } - for(Bot bot : bots) - { - 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(this.items.size() > 0) { + for (Bot bot : bots) { + 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++; + } } } } 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 36a494d3..d2f07557 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 @@ -45,6 +45,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { super(id, userId, item, extradata, limitedStack, limitedSells); this.items = new THashSet<>(); + this.lastDirections = new THashMap<>(); } public List getAvailableDirections(HabboItem item, Room room) { @@ -98,6 +99,9 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect for(HabboItem item : this.items) { + if(item == null) + continue; + // direction the furni will move in RoomUserRotation moveDirection = null; RoomUserRotation lastDirection = lastDirections.get(item.getId()); 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 72e24eef..240ae719 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 @@ -119,6 +119,56 @@ public class WiredEffectTeleport extends InteractionWiredEffect return true; } + public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { + if(roomUnit == null || tile == null) + return; + + Room room = roomUnit.getRoom(); + + if(room == null) + return; + + // makes a temporary effect + room.sendComposer(new RoomUserEffectComposer(roomUnit, 4).compose()); + Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), WiredHandler.TELEPORT_DELAY); + + if (tile.state == RoomTileState.INVALID || tile.state == RoomTileState.BLOCKED) + { + RoomTile alternativeTile = null; + List optionalTiles = room.getLayout().getTilesAround(tile); + + Collections.reverse(optionalTiles); + for (RoomTile optionalTile : optionalTiles) + { + if (optionalTile.state != RoomTileState.INVALID && optionalTile.state != RoomTileState.BLOCKED) + { + alternativeTile = optionalTile; + } + } + + if(alternativeTile != null) { + tile = alternativeTile; + } + } + + 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); + + HabboItem topItem = room.getTopItemAt(tile.x, tile.y); + + if(topItem != null) { + Emulator.getThreading().run(new Runnable() { + @Override + public void run() { + try { + topItem.onWalkOn(roomUnit, room, new Object[] { }); + } catch (Exception e) { + } + } + }, WiredHandler.TELEPORT_DELAY); + } + + } + @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { @@ -146,52 +196,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect tryCount++; HabboItem item = this.items.get((tryCount - 1 + i) % this.items.size()); - int currentEffect = roomUnit.getEffectId(); - - // makes a temporary effect - room.sendComposer(new RoomUserEffectComposer(roomUnit, 4).compose()); - Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), 2000); - - final WiredEffectTeleport teleportWired = this; - RoomTile targetTile = room.getLayout().getTile(item.getX(), item.getY()); - boolean foundTile = false; - if (targetTile.state == RoomTileState.INVALID || targetTile.state == RoomTileState.BLOCKED) - { - List optionalTiles = room.getLayout().getTilesAround(targetTile, item.getRotation() + 3); - - Collections.reverse(optionalTiles); - for (RoomTile tile : optionalTiles) - { - if (tile.state != RoomTileState.INVALID && tile.state != RoomTileState.BLOCKED) - { - targetTile = tile; - foundTile = true; - } - } - } - else - { - foundTile = true; - } - if (!foundTile) - { - continue; - } - - Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, targetTile.x, targetTile.y, targetTile.getStackHeight() + (targetTile.state == RoomTileState.SIT ? -0.5 : 0) , currentEffect), WiredHandler.TELEPORT_DELAY); - Emulator.getThreading().run(new Runnable() - { - @Override - public void run() - { - try - { - item.onWalkOn(roomUnit, room, new Object[]{teleportWired}); - } - catch (Exception e) - {} - } - }, WiredHandler.TELEPORT_DELAY); + teleportUnitToTile(roomUnit, room.getLayout().getTile(item.getX(), item.getY())); break; } 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 69b52a1b..1f2d95ad 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 @@ -133,13 +133,6 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect HabboItem triggerItem = null; - if (stuff != null && stuff.length > 0) - { - if (stuff[0] instanceof HabboItem) - { - } - } - THashSet itemsToRemove = new THashSet<>(); for (HabboItem item : this.items) { @@ -153,7 +146,15 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) { - item.onClick(habbo != null ? habbo.getClient() : null, room, new Object[]{item.getExtradata().length() == 0 ? 0 : Integer.valueOf(item.getExtradata()), this.getType()}); + 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. + } catch (NumberFormatException ignored) { + + } + } + item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{state, this.getType()}); } } catch (Exception e) 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 9e51f95c..675495c5 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 @@ -119,7 +119,7 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length >= 1 && stuff[stuff.length - 1] instanceof WiredEffectTriggerStacks) + if (stuff != null && stuff.length >= 1 && stuff[stuff.length - 1] instanceof WiredEffectTriggerStacks) { return false; } 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 baa1ec6d..5f4c1f48 100644 --- a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java +++ b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java @@ -124,6 +124,11 @@ public class Messenger this.friends.remove(habbo.getHabboInfo().getId()); } + public void addBuddy(MessengerBuddy buddy) + { + this.friends.put(buddy.getId(), buddy); + } + public static void unfriend(int userOne, int userTwo) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM messenger_friendships WHERE (user_one_id = ? AND user_two_id = ?) OR (user_one_id = ? AND user_two_id = ?)")) diff --git a/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java b/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java index 5557a35e..30999fa1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java +++ b/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java @@ -1,15 +1,19 @@ package com.eu.habbo.habbohotel.messenger; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.WordFilter; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.messages.ISerialize; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.friends.FriendChatMessageComposer; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -public class MessengerBuddy implements Runnable { +public class MessengerBuddy implements Runnable, ISerialize { private int id; private String username; @@ -176,4 +180,39 @@ public class MessengerBuddy implements Runnable { Emulator.getLogging().logSQLException(e); } } + + public void onMessageReceived(Habbo from, String message) { + Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(this.id); + + if(habbo == null) + return; + + Message chatMessage = new Message(from.getHabboInfo().getId(), this.id, message); + Emulator.getThreading().run(chatMessage); + + if (WordFilter.ENABLED_FRIENDCHAT) + { + chatMessage.setMessage(Emulator.getGameEnvironment().getWordFilter().filter(chatMessage.getMessage(), from)); + } + + habbo.getClient().sendResponse(new FriendChatMessageComposer(chatMessage)); + } + + @Override + public void serialize(ServerMessage message) { + message.appendInt(this.id); + message.appendString(this.username); + message.appendInt(this.gender.equals(HabboGender.M) ? 0 : 1); + message.appendBoolean(this.online == 1); + message.appendBoolean(this.inRoom); //IN ROOM + message.appendString(this.look); + message.appendInt(0); + message.appendString(this.motto); + message.appendString(""); + message.appendString(""); + message.appendBoolean(false); //Offline messaging. + message.appendBoolean(false); + message.appendBoolean(false); + message.appendShort(this.relation); + } } 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 c97df979..2ef67048 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -473,7 +473,7 @@ public class ModToolManager public void alert(Habbo moderator, Habbo target, String message, SupportUserAlertedReason reason) { if(!moderator.hasPermission(Permission.ACC_SUPPORTTOOL)) { - Emulator.getGameEnvironment().getModToolManager().quickTicket(moderator, "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", moderator.getHabboInfo().getUsername()).replace("%message%", message)); + ScripterManager.scripterDetected(moderator.getClient(), Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", moderator.getHabboInfo().getUsername()).replace("%message%", message)); return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterEvent.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterEvent.java new file mode 100644 index 00000000..82843275 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterEvent.java @@ -0,0 +1,16 @@ +package com.eu.habbo.habbohotel.modtool; + +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.plugin.events.support.SupportEvent; + +public class ScripterEvent extends SupportEvent { + public final Habbo habbo; + public final String reason; + + public ScripterEvent(Habbo habbo, String reason) { + super(null); + + this.habbo = habbo; + this.reason = reason; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterManager.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterManager.java new file mode 100644 index 00000000..a37db651 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ScripterManager.java @@ -0,0 +1,17 @@ +package com.eu.habbo.habbohotel.modtool; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.gameclients.GameClient; + +public class ScripterManager { + public static void scripterDetected(GameClient client, String reason) { + ScripterEvent scripterEvent = new ScripterEvent(client.getHabbo(), reason); + Emulator.getPluginManager().fireEvent(scripterEvent); + + if (scripterEvent.isCancelled()) return; + + if (Emulator.getConfig().getBoolean("scripter.modtool.tickets", true)) { + Emulator.getGameEnvironment().getModToolManager().quickTicket(client.getHabbo(), "Scripter", reason); + } + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java index ba96d138..9f289c91 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java @@ -9,6 +9,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -27,7 +28,6 @@ public class NavigatorManager public NavigatorManager() { long millis = System.currentTimeMillis(); - this.loadNavigator(); this.filters.put(NavigatorPublicFilter.name, new NavigatorPublicFilter()); this.filters.put(NavigatorHotelFilter.name, new NavigatorHotelFilter()); @@ -139,6 +139,12 @@ public class NavigatorManager { Emulator.getLogging().logSQLException(e); } + + List staffPromotedRooms = Emulator.getGameEnvironment().getRoomManager().getRoomsStaffPromoted(); + + for (Room room : staffPromotedRooms) { + this.publicCategories.get(Emulator.getConfig().getInt("hotel.navigator.staffpicks.categoryid")).addRoom(room); + } } public NavigatorFilterComparator comperatorForField(Method field) diff --git a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java index 96ed14d0..828dcad8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java @@ -108,7 +108,7 @@ public class PermissionsManager } - public Rank getRank(String rankName) + public Rank getRankByName(String rankName) { for (Rank rank : this.ranks.valueCollection()) { @@ -161,8 +161,12 @@ public class PermissionsManager return this.badges.keySet(); } - public List getRanks(String code) + public List getRanksByBadgeCode(String code) { return this.badges.get(code); } + + public List getAllRanks() { + return new ArrayList<>(this.ranks.valueCollection()); + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java b/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java index 5a4a879c..f90f7d2d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java @@ -1,31 +1,24 @@ package com.eu.habbo.habbohotel.pets; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.Habbo; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -public class HorsePet extends Pet +public class HorsePet extends RideablePet { private int hairColor; private int hairStyle; - private boolean hasSaddle; - private boolean anyoneCanRide; - - private Habbo rider; - public HorsePet(ResultSet set) throws SQLException { super(set); this.hairColor = set.getInt("hair_color"); this.hairStyle = set.getInt("hair_style"); - this.hasSaddle = set.getString("saddle").equalsIgnoreCase("1"); - this.anyoneCanRide = set.getString("ride").equalsIgnoreCase("1"); - this.rider = null; + this.hasSaddle(set.getString("saddle").equalsIgnoreCase("1")); + this.setAnyoneCanRide(set.getString("ride").equalsIgnoreCase("1")); } public HorsePet(int type, int race, String color, String name, int userId) @@ -33,9 +26,8 @@ public class HorsePet extends Pet super(type, race, color, name, userId); this.hairColor = 0; this.hairStyle = -1; - this.hasSaddle = false; - this.anyoneCanRide = false; - this.rider = null; + this.hasSaddle(false); + this.setAnyoneCanRide(false); } @Override @@ -47,8 +39,8 @@ public class HorsePet extends Pet { statement.setInt(1, this.hairStyle); statement.setInt(2, this.hairColor); - statement.setString(3, this.hasSaddle ? "1" : "0"); - statement.setString(4, this.anyoneCanRide ? "1" : "0"); + statement.setString(3, this.hasSaddle() ? "1" : "0"); + statement.setString(4, this.anyoneCanRide() ? "1" : "0"); statement.setInt(5, super.getId()); statement.execute(); } @@ -80,34 +72,4 @@ public class HorsePet extends Pet { this.hairStyle = hairStyle; } - - public boolean hasSaddle() - { - return this.hasSaddle; - } - - public void hasSaddle(boolean hasSaddle) - { - this.hasSaddle = hasSaddle; - } - - public boolean anyoneCanRide() - { - return this.anyoneCanRide; - } - - public void setAnyoneCanRide(boolean anyoneCanRide) - { - this.anyoneCanRide = anyoneCanRide; - } - - public Habbo getRider() - { - return this.rider; - } - - public void setRider(Habbo rider) - { - this.rider = rider; - } } 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 7688db9c..b28b91ab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -11,6 +11,7 @@ import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.pets.PetLevelUpdatedComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetExperienceComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTalkComposer; import com.eu.habbo.plugin.events.pets.PetTalkEvent; import gnu.trove.map.hash.THashMap; @@ -876,4 +877,24 @@ public class Pet implements ISerialize, Runnable { this.levelHunger = levelHunger; } + + public void removeFromRoom() { + removeFromRoom(false); + } + + public void removeFromRoom(boolean dontSendPackets) { + + if(this.roomUnit != null && this.roomUnit.getCurrentLocation() != null) { + this.roomUnit.getCurrentLocation().removeUnit(this.roomUnit); + } + + if(!dontSendPackets) { + room.sendComposer(new RoomUserRemoveComposer(this.roomUnit).compose()); + room.removePet(this.id); + } + + this.roomUnit = null; + this.room = null; + this.needsUpdate = true; + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java b/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java index 61618cd6..0125b947 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java @@ -79,6 +79,19 @@ public class PetManager this.breedingPetType = new TIntIntHashMap(); this.breedingReward = new THashMap<>(); + reloadPetData(); + + Emulator.getLogging().logStart("Pet Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); + } + + + public void reloadPetData() + { + this.petRaces.clear(); + this.petData.clear(); + this.breedingPetType.clear(); + this.breedingReward.clear(); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { this.loadRaces(connection); @@ -90,55 +103,6 @@ public class PetManager { Emulator.getLogging().logSQLException(e); Emulator.getLogging().logErrorLine("Pet Manager -> Failed to load!"); - return; - } - - Emulator.getLogging().logStart("Pet Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); - } - - - public void reloadPetData() - { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) - { - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM pet_actions ORDER BY pet_type ASC")) - { - try (ResultSet set = statement.executeQuery()) - { - while (set.next()) - { - PetData petData = this.petData.get(set.getInt("pet_type")); - - if (petData != null) - { - petData.load(set); - } - else - { - this.petData.put(set.getInt("pet_type"), new PetData(set)); - } - } - } - } - - PetData.generalNestItems.clear(); - PetData.generalFoodItems.clear(); - PetData.generalDrinkItems.clear(); - - for(PetData data : this.petData.values()) - { - data.reset(); - } - - this.loadPetItems(connection); - - this.loadPetVocals(connection); - - this.loadRaces(connection); - } - catch (SQLException e) - { - Emulator.getLogging().logSQLException(e); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java b/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java new file mode 100644 index 00000000..db9f11c9 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java @@ -0,0 +1,53 @@ +package com.eu.habbo.habbohotel.pets; + +import com.eu.habbo.habbohotel.users.Habbo; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class RideablePet extends Pet { + + private Habbo rider; + private boolean hasSaddle; + private boolean anyoneCanRide; + + public RideablePet(ResultSet set) throws SQLException { + super(set); + this.rider = null; + } + + public RideablePet(int type, int race, String color, String name, int userId) { + super(type, race, color, name, userId); + this.rider = null; + } + + public boolean hasSaddle() + { + return this.hasSaddle; + } + + public void hasSaddle(boolean hasSaddle) + { + this.hasSaddle = hasSaddle; + } + + public boolean anyoneCanRide() + { + return this.anyoneCanRide; + } + + public void setAnyoneCanRide(boolean anyoneCanRide) + { + this.anyoneCanRide = anyoneCanRide; + } + + public Habbo getRider() + { + return this.rider; + } + + public void setRider(Habbo rider) + { + this.rider = rider; + } +} 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 9c677d16..0aa1fd87 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -22,10 +22,9 @@ import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.pets.HorsePet; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetManager; -import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.users.*; import com.eu.habbo.habbohotel.wired.*; import com.eu.habbo.messages.ISerialize; @@ -54,6 +53,7 @@ import com.eu.habbo.plugin.events.users.UserExitRoomEvent; import com.eu.habbo.plugin.events.users.UserIdleEvent; import com.eu.habbo.plugin.events.users.UserRightsTakenEvent; import com.eu.habbo.plugin.events.users.UserRolledEvent; +import com.eu.habbo.threading.runnables.RoomUnitRidePet; import com.eu.habbo.threading.runnables.YouAreAPirate; import gnu.trove.TCollections; import gnu.trove.iterator.TIntObjectIterator; @@ -639,7 +639,7 @@ public class Room implements Comparable, ISerialize, Runnable private RoomTileState calculateTileState(RoomTile tile, HabboItem exclude) { - if (tile.state == RoomTileState.INVALID) + if (tile == null || tile.state == RoomTileState.INVALID) return RoomTileState.INVALID; RoomTileState result = RoomTileState.OPEN; @@ -703,59 +703,17 @@ public class Room implements Comparable, ISerialize, Runnable public boolean tileWalkable(short x, short y) { boolean walkable = this.layout.tileWalkable(x, y); + RoomTile tile = this.getLayout().getTile(x, y); - if (walkable) + if (walkable && tile != null) { - if (this.hasHabbosAt(x, y) && !this.allowWalkthrough) + if (tile.hasUnits() && !this.allowWalkthrough) { walkable = false; } } - return walkable; //&& (!this.allowWalkthrough && !this.hasHabbosAt(x, y))); - //if(this.layout.tileWalkable(x, y)) - - - - - -// - - - -// - - - -// - - - - - -// - - -// - - - - - - - - - - - - - -// - - -// - - + return walkable; } public void pickUpItem(HabboItem item, Habbo picker) @@ -803,6 +761,7 @@ public class Room implements Comparable, ISerialize, Runnable for (RoomTile tile : updatedTiles) { this.updateHabbosAt(tile.x, tile.y); + this.updateBotsAt(tile.x, tile.y); } } else if (item.getBaseItem().getType() == FurnitureType.WALL) @@ -851,7 +810,7 @@ public class Room implements Comparable, ISerialize, Runnable } else { - roomUnit.setZ(item.getZ() + item.getBaseItem().getHeight()); + roomUnit.setZ(item.getZ() + Item.getCurrentHeight(item)); } if (oldZ != roomUnit.getZ()) @@ -893,7 +852,7 @@ public class Room implements Comparable, ISerialize, Runnable if(item != null) { - if(item.getBaseItem().allowSit()) + if(item.getBaseItem().allowSit() || item.getBaseItem().allowLay()) { habbo.getRoomUnit().setZ(item.getZ()); habbo.getRoomUnit().setPreviousLocationZ(item.getZ()); @@ -901,12 +860,7 @@ public class Room implements Comparable, ISerialize, Runnable } else { - habbo.getRoomUnit().setZ(item.getZ() + item.getBaseItem().getHeight()); - - if (item.getBaseItem().allowLay()) - { - habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + item.getBaseItem().getHeight()) + ""); - } + habbo.getRoomUnit().setZ(item.getZ() + Item.getCurrentHeight(item)); } } else @@ -923,6 +877,41 @@ public class Room implements Comparable, ISerialize, Runnable } } + private void updateBotsAt(short x, short y) + { + HabboItem topItem = this.getTopItemAt(x, y); + + THashSet roomUnits = new THashSet<>(); + + for (Bot bot: this.getBotsAt(this.layout.getTile(x, y))) { + if (topItem != null) + { + if (topItem.getBaseItem().allowSit()) + { + bot.getRoomUnit().setZ(topItem.getZ()); + bot.getRoomUnit().setPreviousLocationZ(topItem.getZ()); + bot.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation())); + } else{ + bot.getRoomUnit().setZ(topItem.getZ() + topItem.getBaseItem().getHeight()); + + if (topItem.getBaseItem().allowLay()) + { + bot.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + ""); + } + } + } else { + bot.getRoomUnit().setZ(bot.getRoomUnit().getCurrentLocation().getStackHeight()); + } + + roomUnits.add(bot.getRoomUnit()); + } + + if (!roomUnits.isEmpty()) + { + this.sendComposer(new RoomUserStatusComposer(roomUnits, true).compose()); + } + } + public void pickupPetsForHabbo(Habbo habbo) { THashSet pets = new THashSet<>(); @@ -940,10 +929,9 @@ public class Room implements Comparable, ISerialize, Runnable for(Pet pet : pets) { - pet.setRoom(null); - pet.needsUpdate = true; + pet.removeFromRoom(); + Emulator.getThreading().run(pet); habbo.getInventory().getPetsComponent().addPet(pet); - this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); habbo.getClient().sendResponse(new AddPetComposer(pet)); this.currentPets.remove(pet.getId()); } @@ -1015,12 +1003,18 @@ public class Room implements Comparable, ISerialize, Runnable this.mutedHabbos.clear(); } + for(InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) { + timer.setRunning(false); + } + for (Game game : this.games) { game.stop(); } this.games.clear(); + removeAllPets(ownerId); + synchronized (this.roomItems) { TIntObjectIterator iterator = this.roomItems.iterator(); @@ -1084,22 +1078,6 @@ public class Room implements Comparable, ISerialize, Runnable } } - TIntObjectIterator petIterator = this.currentPets.iterator(); - for (int i = this.currentPets.size(); i-- > 0; ) - { - try - { - petIterator.advance(); - petIterator.value().needsUpdate = true; - Emulator.getThreading().run(petIterator.value()); - } - catch (NoSuchElementException e) - { - Emulator.getLogging().logErrorLine(e); - break; - } - } - this.currentBots.clear(); this.currentPets.clear(); } catch (Exception e) @@ -1569,21 +1547,6 @@ public class Room implements Comparable, ISerialize, Runnable pet.packetUpdate = false; } - if (pet.getTask() == PetTasks.RIDE) - { - if (pet instanceof HorsePet) - { - HorsePet horse = ((HorsePet) pet); - if (horse.getRider() != null) - { - if (!horse.getRider().getRoomUnit().getCurrentLocation().equals(horse.getRoomUnit().getCurrentLocation())) - { - horse.getRoomUnit().setGoalLocation(horse.getRider().getRoomUnit().getCurrentLocation()); - } - } - } - } - if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); @@ -1604,243 +1567,268 @@ public class Room implements Comparable, ISerialize, Runnable List rollerFurniIds = new ArrayList<>(); List rolledUnitIds = new ArrayList<>(); - this.roomSpecialTypes.getRollers().forEachValue(new TObjectProcedure() - { - @Override - public boolean execute(InteractionRoller roller) + + this.roomSpecialTypes.getRollers().forEachValue(roller -> { + + HabboItem newRoller = null; + + RoomTile rollerTile = this.getLayout().getTile(roller.getX(), roller.getY()); + + if(rollerTile == null) + return true; + + THashSet itemsOnRoller = new THashSet<>(); + + for(HabboItem item : getItemsAt(rollerTile)) { - //if(Double.compare(roller.getZ(), this.layout.getHeightAtSquare(roller.getX(), roller.getY())) != 0) - - - //} - - HabboItem newRoller = null; - - THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); - THashSet itemsOnRoller = new THashSet<>(); - - RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); - - for(HabboItem item : getItemsAt(rollerTile)) - { + if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { itemsOnRoller.add(item); } + } - itemsOnRoller.remove(roller); + // itemsOnRoller.addAll(this.getItemsAt(rollerTile)); + itemsOnRoller.remove(roller); - if (habbosOnRoller.isEmpty()) + if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty()) + return true; + + RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation()); + + if (tileInFront == null) + return true; + + if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y)) + return true; + + if (tileInFront.state == RoomTileState.INVALID) + return true; + + if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY)) + return true; + + if (tileInFront.hasUnits()) + return true; + + THashSet itemsNewTile = new THashSet<>(); + itemsNewTile.addAll(getItemsAt(tileInFront)); + itemsNewTile.removeAll(itemsOnRoller); + + List toRemove = new ArrayList<>(); + for (HabboItem item : itemsOnRoller) + { + if (item.getX() != roller.getX() || item.getY() != roller.getY() || rollerFurniIds.contains(item.getId())) { - if (itemsOnRoller.isEmpty()) - return true; + toRemove.add(item); } + } + itemsOnRoller.removeAll(toRemove); + HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y); - RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation()); + boolean allowUsers = true; + boolean allowFurniture = true; + boolean stackContainsRoller = false; - if (tileInFront == null) - return true; - - - if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y)) - return true; - - if (tileInFront.state == RoomTileState.INVALID) - return true; - - if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY)) - return true; - - if (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) - return true; - - THashSet itemsNewTile = new THashSet<>(); - - for(HabboItem item : getItemsAt(tileInFront)) + for (HabboItem item : itemsNewTile) + { + if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1"))) { - itemsNewTile.add(item); + allowUsers = false; } - - itemsNewTile.removeAll(itemsOnRoller); - List toRemove = new ArrayList<>(); - for (HabboItem item : itemsOnRoller) + if (item instanceof InteractionRoller) { - if (item.getX() != roller.getX() || item.getY() != roller.getY() || rollerFurniIds.contains(item.getId())) - { - toRemove.add(item); - } - } - itemsOnRoller.removeAll(toRemove); - HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y); + newRoller = item; + stackContainsRoller = true; - boolean allowUsers = true; - boolean allowFurniture = true; - boolean stackContainsRoller = false; - - for (HabboItem item : itemsNewTile) - { - if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1"))) + if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) { allowUsers = false; - } - if (item instanceof InteractionRoller) - { - newRoller = item; - stackContainsRoller = true; - - if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) - { - allowUsers = false; - allowFurniture = false; - continue; - } - - break; - } else - { allowFurniture = false; + continue; } - } - if (allowFurniture) + break; + } else { - allowFurniture = tileInFront.getAllowStack(); + allowFurniture = false; } - - double zOffset = 0; - if (newRoller != null) - { - if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES) - { - return true; - } - } - else - { - zOffset = -roller.getBaseItem().getHeight() + tileInFront.getStackHeight() - rollerTile.z; - } - - if (allowUsers) - { - Event roomUserRolledEvent = null; - - if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true)) - { - roomUserRolledEvent = new UserRolledEvent(null, null, null); - } - - for (Habbo habbo : habbosOnRoller) - { - if (rolledUnitIds.contains(habbo.getRoomUnit().getId())) continue; - - rolledUnitIds.add(habbo.getRoomUnit().getId()); - - if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) - continue; - - if (!habbo.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) - { - RoomTile tile = tileInFront.copy(); - tile.setStackHeight(habbo.getRoomUnit().getZ() + zOffset); - if (roomUserRolledEvent != null) - { - roomUserRolledEvent = new UserRolledEvent(habbo, roller, tile); - Emulator.getPluginManager().fireEvent(roomUserRolledEvent); - - if (roomUserRolledEvent.isCancelled()) - continue; - } - - updatedUnit.remove(habbo.getRoomUnit()); - messages.add(new RoomUnitOnRollerComposer(habbo.getRoomUnit(), roller, habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getZ(), tile, tile.getStackHeight(), room)); - - if (itemsOnRoller.isEmpty()) - { - HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); - - if (item != null && itemsNewTile.contains(item)) - { - try - { - item.onWalkOn(habbo.getRoomUnit(), room, null); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - } - } - } - } - - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) - habbo.getRoomUnit().sitUpdate = true; - - break; - } - } - - if (!messages.isEmpty()) - { - for (MessageComposer message : messages) - { - room.sendComposer(message.compose()); - } - messages.clear(); - } - - if ((allowFurniture || !stackContainsRoller) && !InteractionRoller.NO_RULES) - { - Event furnitureRolledEvent = null; - - if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true)) - { - furnitureRolledEvent = new FurnitureRolledEvent(null, null, null); - } - - if (newRoller == null || topItem == newRoller) - { - List sortedItems = new ArrayList<>(itemsOnRoller); - sortedItems.sort(new Comparator() - { - @Override - public int compare(HabboItem o1, HabboItem o2) - { - return o1.getZ() > o2.getZ() ? -1 : 1; - } - }); - - for (HabboItem item : sortedItems) - { - if (item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0) - { - if (item != roller) - { - if (furnitureRolledEvent != null) - { - furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront); - Emulator.getPluginManager().fireEvent(furnitureRolledEvent); - - if (furnitureRolledEvent.isCancelled()) - continue; - } - - messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room)); - rollerFurniIds.add(item.getId()); - } - } - } - } - } - - - if (!messages.isEmpty()) - { - for (MessageComposer message : messages) - { - room.sendComposer(message.compose()); - } - messages.clear(); - } - - return true; } + + if (allowFurniture) + { + allowFurniture = tileInFront.getAllowStack(); + } + + double zOffset = 0; + if (newRoller != null) + { + if ((!itemsNewTile.isEmpty() && (itemsNewTile.size() > 1)) && !InteractionRoller.NO_RULES) + { + return true; + } + } + else + { + zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.z; + } + + if (allowUsers) + { + Event roomUserRolledEvent = null; + + if (Emulator.getPluginManager().isRegistered(UserRolledEvent.class, true)) + { + roomUserRolledEvent = new UserRolledEvent(null, null, null); + } + + ArrayList unitsOnTile = new ArrayList(rollerTile.getUnits()); + + for(RoomUnit unit : rollerTile.getUnits()) { + if(unit.getRoomUnitType() == RoomUnitType.PET) { + Pet pet = this.getPet(unit); + if (pet instanceof RideablePet && ((RideablePet) pet).getRider() != null) { + unitsOnTile.remove(unit); + } + } + } + + HabboItem nextTileChair = this.getLowestChair(tileInFront); + + for(RoomUnit unit : unitsOnTile) { + if (rolledUnitIds.contains(unit.getId())) continue; + + if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) + continue; + + if(unit.hasStatus(RoomUnitStatus.MOVE)) + continue; + + RoomTile tile = tileInFront.copy(); + tile.setStackHeight(unit.getZ() + zOffset); + + if (roomUserRolledEvent != null && unit.getRoomUnitType() == RoomUnitType.USER) + { + roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tile); + Emulator.getPluginManager().fireEvent(roomUserRolledEvent); + + if (roomUserRolledEvent.isCancelled()) + continue; + } + + // horse riding + boolean isRiding = false; + if(unit.getRoomUnitType() == RoomUnitType.USER) { + Habbo rollingHabbo = this.getHabbo(unit); + if(rollingHabbo != null && rollingHabbo.getHabboInfo() != null) { + RideablePet riding = rollingHabbo.getHabboInfo().getRiding(); + if (riding != null) { + RoomUnit ridingUnit = riding.getRoomUnit(); + tile.setStackHeight(ridingUnit.getZ() + zOffset); + rolledUnitIds.add(ridingUnit.getId()); + updatedUnit.remove(ridingUnit); + messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, tile.getStackHeight() + (nextTileChair != null ? -1 : 0), room)); + isRiding = true; + } + } + } + + 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)); + + if (itemsOnRoller.isEmpty()) + { + HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); + + if (item != null && itemsNewTile.contains(item)) + { + Emulator.getThreading().run(new Runnable() { + @Override + public void run() { + if (unit.getGoal() == rollerTile) + { + try + { + item.onWalkOn(unit, room, null); + } catch (Exception e) + { + Emulator.getLogging().logErrorLine(e); + } + } + } + }, 500); + } + } + + if(unit.hasStatus(RoomUnitStatus.SIT)) { + unit.sitUpdate = true; + } + } + } + + if (!messages.isEmpty()) + { + for (MessageComposer message : messages) + { + room.sendComposer(message.compose()); + } + messages.clear(); + } + + if (allowFurniture || !stackContainsRoller || InteractionRoller.NO_RULES) + { + Event furnitureRolledEvent = null; + + if (Emulator.getPluginManager().isRegistered(FurnitureRolledEvent.class, true)) + { + furnitureRolledEvent = new FurnitureRolledEvent(null, null, null); + } + + if (newRoller == null || topItem == newRoller) + { + List sortedItems = new ArrayList<>(itemsOnRoller); + sortedItems.sort(new Comparator() + { + @Override + public int compare(HabboItem o1, HabboItem o2) + { + return o1.getZ() > o2.getZ() ? -1 : 1; + } + }); + + for (HabboItem item : sortedItems) + { + if (item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0) + { + if (item != roller) + { + if (furnitureRolledEvent != null) + { + furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront); + Emulator.getPluginManager().fireEvent(furnitureRolledEvent); + + if (furnitureRolledEvent.isCancelled()) + continue; + } + + messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room)); + rollerFurniIds.add(item.getId()); + } + } + } + } + } + + + if (!messages.isEmpty()) + { + for (MessageComposer message : messages) + { + room.sendComposer(message.compose()); + } + messages.clear(); + } + + return true; }); @@ -1943,7 +1931,7 @@ public class Room implements Comparable, ISerialize, Runnable if (!unit.isWalking() && !unit.cmdSit) { - HabboItem topItem = this.getLowestChair(unit.getX(), unit.getY()); + HabboItem topItem = this.getLowestChair(this.getLayout().getTile(unit.getX(), unit.getY())); if (topItem == null || !topItem.getBaseItem().allowSit()) { @@ -1958,16 +1946,10 @@ public class Room implements Comparable, ISerialize, Runnable if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate) { this.dance(unit, DanceType.NONE); - int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z; - if (topItem instanceof InteractionMultiHeight) - { - unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + ""); - } - else - { - unit.setStatus(RoomUnitStatus.SIT, (topItem.getBaseItem().getHeight() * 1.0D) + ""); - } + //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z; + unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + ""); unit.setPreviousLocationZ(topItem.getZ()); + unit.setZ(topItem.getZ()); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); unit.sitUpdate = false; return true; @@ -1992,14 +1974,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (!unit.hasStatus(RoomUnitStatus.LAY)) { - if (topItem instanceof InteractionMultiHeight) - { - unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + ""); - } - else - { - unit.setStatus(RoomUnitStatus.LAY, topItem.getBaseItem().getHeight() * 1.0D + ""); - } + unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + ""); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); if (topItem.getRotation() == 0 || topItem.getRotation() == 4) @@ -2399,6 +2374,47 @@ public class Room implements Comparable, ISerialize, Runnable public void setAllowPets(boolean allowPets) { this.allowPets = allowPets; + if(!allowPets) { + removeAllPets(ownerId); + } + } + + public void removeAllPets() { + removeAllPets(-1); + } + + /** + * Removes all pets from the room except if the owner id is excludeUserId + * @param excludeUserId Habbo id to keep pets + */ + public void removeAllPets(int excludeUserId) { + ArrayList removedPets = new ArrayList<>(); + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.valueCollection()) { + try { + if (pet.getUserId() != excludeUserId) { + + pet.removeFromRoom(); + + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); + if (habbo != null) { + habbo.getInventory().getPetsComponent().addPet(pet); + habbo.getClient().sendResponse(new AddPetComposer(pet)); + } + } + + pet.needsUpdate = true; + pet.run(); + } catch (NoSuchElementException e) { + Emulator.getLogging().logErrorLine(e); + break; + } + } + } + + for (Pet pet : removedPets) { + this.currentPets.remove(pet.getId()); + } } public void setAllowPetsEat(boolean allowPetsEat) @@ -3178,8 +3194,20 @@ public class Room implements Comparable, ISerialize, Runnable } } - public void removeHabbo(Habbo habbo) + public void removeHabbo(Habbo habbo) { + removeHabbo(habbo, false); + } + + public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { + if(habbo.getRoomUnit() != null && habbo.getRoomUnit().getCurrentLocation() != null) { + habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit()); + } + + if(sendRemovePacket && habbo.getRoomUnit() != null) { + this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); + } + HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); if (item != null) @@ -3214,6 +3242,11 @@ public class Room implements Comparable, ISerialize, Runnable trade.stopTrade(habbo); } + if (habbo.getHabboInfo().getId() != this.ownerId) + { + this.pickupPetsForHabbo(habbo); + } + this.updateDatabaseUserCount(); } @@ -3387,6 +3420,10 @@ public class Room implements Comparable, ISerialize, Runnable { if (this.currentBots.containsKey(bot.getId())) { + if(bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentLocation() != null) { + bot.getRoomUnit().getCurrentLocation().removeUnit(bot.getRoomUnit()); + } + this.currentBots.remove(bot.getId()); bot.getRoomUnit().setInRoom(false); bot.setRoom(null); @@ -3549,7 +3586,7 @@ public class Room implements Comparable, ISerialize, Runnable public void teleportHabboToItem(Habbo habbo, HabboItem item) { - this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); + this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); } public void teleportHabboToLocation(Habbo habbo, short x, short y) @@ -3559,7 +3596,7 @@ public class Room implements Comparable, ISerialize, Runnable public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item) { - this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); + this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); } public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y) @@ -3646,7 +3683,7 @@ public class Room implements Comparable, ISerialize, Runnable } HabboItem doorTileTopItem = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); - if (doorTileTopItem != null) + if (doorTileTopItem != null && !(doorTileTopItem instanceof InteractionTeleportTile)) { try { @@ -3676,6 +3713,14 @@ public class Room implements Comparable, ISerialize, Runnable if (!habbo.getHabboStats().allowTalk()) return; + if (habbo.getRoomUnit().isInvisible() && Emulator.getConfig().getBoolean("invisible.prevent.chat", false)) { + if (!CommandHandler.handleCommand(habbo.getClient(), roomChatMessage.getUnfilteredMessage())) { + habbo.whisper(Emulator.getTexts().getValue("invisible.prevent.chat.error")); + } + + return; + } + habbo.getHabboStats().chatCounter += 2; if (habbo.getHabboInfo().getCurrentRoom() != this) @@ -4002,6 +4047,9 @@ public class Room implements Comparable, ISerialize, Runnable THashSet items = new THashSet<>(0); + if (tile == null) + return items; + TIntObjectIterator iterator = this.roomItems.iterator(); for (int i = this.roomItems.size(); i-- > 0; ) @@ -4017,6 +4065,9 @@ public class Room implements Comparable, ISerialize, Runnable break; } + if (item == null) + continue; + if (item.getBaseItem().getType() != FurnitureType.FLOOR) continue; @@ -4187,7 +4238,8 @@ public class Room implements Comparable, ISerialize, Runnable { item = habboItem; } - } else + } + else { if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) { @@ -4219,7 +4271,7 @@ public class Room implements Comparable, ISerialize, Runnable HabboItem item = this.getTopItemAt(x, y); if(item != null) - return (item.getZ() + item.getBaseItem().getHeight()); + return (item.getZ() + Item.getCurrentHeight(item)); else return this.layout.getHeightAtSquare(x, y); } @@ -4269,7 +4321,7 @@ public class Room implements Comparable, ISerialize, Runnable public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) { - if(x < 0 || y < 0) + if(x < 0 || y < 0 || this.layout == null) return calculateHeightmap ? Short.MAX_VALUE : 0.0; double height = this.layout.getHeightAtSquare(x, y); @@ -4298,6 +4350,12 @@ public class Room implements Comparable, ISerialize, Runnable canStack = item.getBaseItem().allowStack(); height = item.getZ() + Item.getCurrentHeight(item); } + + HabboItem lowestChair = this.getLowestChair(x, y); + if(lowestChair != null && lowestChair != exclude) { + canStack = true; + height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair); + } } } @@ -4599,7 +4657,7 @@ public class Room implements Comparable, ISerialize, Runnable if(Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(habbo.getHabboInfo().getId()) != null) return 3; - if(guild.getRights() == 0) + if(guild.getRights()) { return 2; } @@ -5043,12 +5101,15 @@ public class Room implements Comparable, ISerialize, Runnable { if(guild.getRoomId() == this.id) { - THashMap admins = Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild); + THashSet members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId()); for (Habbo habbo : this.getHabbos()) { - GuildMember member = admins.get(habbo.getHabboInfo().getId()); - habbo.getClient().sendResponse(new GuildInfoComposer(guild, habbo.getClient(), false, member)); + Optional member = members.stream().filter(m -> m.getUserId() == habbo.getHabboInfo().getId()).findAny(); + + if (!member.isPresent()) continue; + + habbo.getClient().sendResponse(new GuildInfoComposer(guild, habbo.getClient(), false, member.get())); } } @@ -5404,23 +5465,24 @@ public class Room implements Comparable, ISerialize, Runnable if (this.hasPetsAt(t.x, t.y)) return FurnitureMovementError.TILE_HAS_PETS; } - List>> tileFurniList = new ArrayList<>(); - for (RoomTile t : occupiedTiles) - { - tileFurniList.add(Pair.create(t, this.getItemsAt(t))); + boolean magicTile = item instanceof InteractionStackHelper; - HabboItem topItem = this.getTopItemAt(t.x, t.y, item); - if (topItem != null && !topItem.getBaseItem().allowStack()) - { + if(!magicTile) { + List>> tileFurniList = new ArrayList<>(); + for (RoomTile t : occupiedTiles) { + tileFurniList.add(Pair.create(t, this.getItemsAt(t))); + + HabboItem topItem = this.getTopItemAt(t.x, t.y, item); + if (topItem != null && !topItem.getBaseItem().allowStack() && !t.getAllowStack()) { + return FurnitureMovementError.CANT_STACK; + } + } + + if (!item.canStackAt(this, tileFurniList)) { return FurnitureMovementError.CANT_STACK; } } - if (!item.canStackAt(this, tileFurniList)) - { - return FurnitureMovementError.CANT_STACK; - } - return FurnitureMovementError.NONE; } public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) throws Exception @@ -5462,6 +5524,7 @@ public class Room implements Comparable, ISerialize, Runnable for (RoomTile t : occupiedTiles) { this.updateHabbosAt(t.x, t.y); + this.updateBotsAt(t.x, t.y); } Emulator.getThreading().run(item); @@ -5585,6 +5648,7 @@ public class Room implements Comparable, ISerialize, Runnable for (RoomTile t : occupiedTiles) { this.updateHabbosAt(t.x, t.y); + this.updateBotsAt(t.x, t.y); } return FurnitureMovementError.NONE; } @@ -5633,9 +5697,32 @@ public class Room implements Comparable, ISerialize, Runnable for (RoomTile t : occupiedTiles) { this.updateHabbosAt(t.x, t.y); + this.updateBotsAt(t.x, t.y); } return FurnitureMovementError.NONE; } + public THashSet getRoomUnits() { + THashSet units = new THashSet<>(); + for (Habbo habbo : this.currentHabbos.values()) { + if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(habbo.getRoomUnit()); + } + } + + for (Pet pet : this.currentPets.valueCollection()) { + if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(pet.getRoomUnit()); + } + } + + for (Bot bot : this.currentBots.valueCollection()) { + if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom().getId() == this.getId()) { + units.add(bot.getRoomUnit()); + } + } + + return units; + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java index 6b7a7dde..1bcbdf0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -1,6 +1,9 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.users.Habbo; import gnu.trove.set.hash.THashSet; import java.awt.*; @@ -259,7 +262,7 @@ public class RoomLayout return this.heightmap.replace("\r\n", "\r"); } - public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation) + public final Deque findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation, RoomUnit roomUnit) { LinkedList openList = new LinkedList<>(); try @@ -274,7 +277,7 @@ public class RoomLayout long startMillis = System.currentTimeMillis(); while (true) { - if (System.currentTimeMillis() - startMillis > 25) + if (System.currentTimeMillis() - startMillis > 50) { return new LinkedList<>(); } @@ -293,10 +296,16 @@ public class RoomLayout { if (closedList.contains(currentAdj)) continue; + if(roomUnit.canOverrideTile(currentAdj) || (currentAdj.state != RoomTileState.BLOCKED && currentAdj.x == doorX && currentAdj.y == doorY)) { + currentAdj.setPrevious(current); + currentAdj.sethCosts(this.findTile(openList, newTile.x, newTile.y)); + currentAdj.setgCosts(current); + openList.add(currentAdj); + continue; + } + //If the tile is sitable or layable and its not our goal tile, we cannot walk over it. - if ( - (currentAdj.state == RoomTileState.BLOCKED) || - ((currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY) && !currentAdj.equals(goalLocation))) + if (!currentAdj.equals(goalLocation) && (currentAdj.state == RoomTileState.BLOCKED || currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY)) { closedList.add(currentAdj); openList.remove(currentAdj); @@ -311,10 +320,10 @@ public class RoomLayout if (!ALLOW_FALLING && height < - MAXIMUM_STEP_HEIGHT) continue; //If the step difference is bigger than the maximum step height, continue. - if (height > MAXIMUM_STEP_HEIGHT && currentAdj.state == RoomTileState.OPEN) continue; + if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; //Check if the tile has habbos. - if (!this.room.isAllowWalkthrough() && this.room.hasHabbosAt(currentAdj.x, currentAdj.y)) + if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { closedList.add(currentAdj); openList.remove(currentAdj); @@ -654,6 +663,28 @@ public class RoomLayout return tiles; } + public List getWalkableTilesAround(RoomTile tile) { + return getWalkableTilesAround(tile, 0); + } + + public List getWalkableTilesAround(RoomTile tile, int directionOffset) { + List availableTiles = new ArrayList<>(this.getTilesAround(tile, directionOffset)); + + List toRemove = new ArrayList<>(); + + for(RoomTile t : availableTiles) { + if(t == null || t.state != RoomTileState.OPEN || !t.isWalkable()) { + toRemove.add(t); + } + } + + for(RoomTile t : toRemove) { + availableTiles.remove(t); + } + + return availableTiles; + } + public static Rectangle getRectangle(int x, int y, int width, int length, int rotation) { rotation = (rotation % 8); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 9e43752f..aca433aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -4,6 +4,14 @@ import com.eu.habbo.Emulator; import com.eu.habbo.core.RoomUserPetComposer; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.games.Game; +import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; +import com.eu.habbo.habbohotel.games.football.FootballGame; +import com.eu.habbo.habbohotel.games.freeze.FreezeGame; +import com.eu.habbo.habbohotel.games.tag.BunnyrunGame; +import com.eu.habbo.habbohotel.games.tag.IceTagGame; +import com.eu.habbo.habbohotel.games.tag.RollerskateGame; +import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.messenger.MessengerBuddy; @@ -34,6 +42,7 @@ import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer; import com.eu.habbo.plugin.events.navigator.NavigatorRoomCreatedEvent; import com.eu.habbo.plugin.events.rooms.RoomUncachedEvent; +import com.eu.habbo.plugin.events.users.HabboAddedToRoomEvent; import com.eu.habbo.plugin.events.users.UserEnterRoomEvent; import com.eu.habbo.plugin.events.users.UserExitRoomEvent; import gnu.trove.iterator.TIntObjectIterator; @@ -57,6 +66,7 @@ public class RoomManager private final THashMap roomCategories; private final List mapNames; private final ConcurrentHashMap activeRooms; + private final ArrayList> gameTypes; public RoomManager() { @@ -67,6 +77,16 @@ public class RoomManager this.loadRoomCategories(); this.loadRoomModels(); + this.gameTypes = new ArrayList<>(); + + registerGameType(BattleBanzaiGame.class); + registerGameType(FreezeGame.class); + registerGameType(WiredGame.class); + registerGameType(FootballGame.class); + registerGameType(BunnyrunGame.class); + registerGameType(IceTagGame.class); + registerGameType(RollerskateGame.class); + Emulator.getLogging().logStart("Room Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); } @@ -692,8 +712,23 @@ public class RoomManager habbo.getRoomUnit().clearStatus(); if (habbo.getRoomUnit().getCurrentLocation() == null) { - habbo.getRoomUnit().setLocation(room.getLayout().getDoorTile()); + habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile()); + habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight()); + + if(doorLocation == null) { + habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); + habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); + } + else { + habbo.getRoomUnit().setCanLeaveRoomByDoor(false); + habbo.getRoomUnit().isTeleporting = true; + HabboItem topItem = room.getTopItemAt(doorLocation.x, doorLocation.y); + if(topItem != null) { + habbo.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]); + } + } } + habbo.getRoomUnit().setRoomUnitType(RoomUnitType.USER); if(room.isBanned(habbo)) { @@ -716,7 +751,8 @@ public class RoomManager if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null) { habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo); - } else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null) + } + else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null) { habbo.getMessenger().connectionChanged(habbo, true, true); } @@ -732,11 +768,6 @@ public class RoomManager habbo.getHabboInfo().setLoadingRoom(room.getId()); - if (habbo.getRoomUnit().isTeleporting) - { - habbo.getRoomUnit().setLocation(doorLocation); - } - habbo.getClient().sendResponse(new RoomModelComposer(room)); if (!room.getWallPaint().equals("0.0")) @@ -793,9 +824,8 @@ public class RoomManager } habbo.getRoomUnit().isKicked = false; - if (!habbo.getRoomUnit().isTeleporting) + if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting) { - RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); if (doorTile != null) @@ -807,6 +837,7 @@ public class RoomManager habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); } + habbo.getRoomUnit().setPathFinderRoom(room); habbo.getRoomUnit().resetIdleTimer(); @@ -1041,6 +1072,10 @@ public class RoomManager { UserNuxEvent.handle(habbo); } + + if(Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) { + Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room)); + } } void logEnter(Habbo habbo, Room room) @@ -1070,14 +1105,9 @@ public class RoomManager { habbo.getRoomUnit().setPathFinderRoom(null); - if (!room.isOwner(habbo)) - { - room.pickupPetsForHabbo(habbo); - } this.logExit(habbo); - room.removeHabbo(habbo); + room.removeHabbo(habbo, true); - room.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); if (redirectToHotelView) { habbo.getClient().sendResponse(new HotelViewComposer()); @@ -1572,6 +1602,20 @@ public class RoomManager return r; } + public ArrayList getRoomsStaffPromoted() { + ArrayList r = new ArrayList<>(); + + for(Room room : this.getActiveRooms()) + { + if(room.isStaffPromotedRoom()) + { + r.add(room); + } + } + + return r; + } + public List filterRoomsByOwner(List rooms, String filter) { ArrayList r = new ArrayList<>(); @@ -1751,4 +1795,16 @@ public class RoomManager this.duration = duration; } } + + public void registerGameType(Class gameClass) { + gameTypes.add(gameClass); + } + + public void unregisterGameType(Class gameClass) { + gameTypes.remove(gameClass); + } + + public ArrayList> getGameTypes() { + return gameTypes; + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java index afb9993d..0c18a1d3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java @@ -774,43 +774,6 @@ public class RoomSpecialTypes return this.gameTimers; } - public THashMap getFreezeTimers() - { - synchronized (this.gameTimers) - { - THashMap timers = new THashMap<>(); - - for (Map.Entry set : this.gameTimers.entrySet()) - { - if (set.getValue() instanceof InteractionFreezeTimer) - { - timers.put(set.getValue().getId(), (InteractionFreezeTimer) set.getValue()); - } - } - - return timers; - } - } - - public THashMap getBattleBanzaiTimers() - { - synchronized (this.gameTimers) - { - THashMap timers = new THashMap<>(); - - for (Map.Entry set : this.gameTimers.entrySet()) - { - if (set.getValue() instanceof InteractionBattleBanzaiTimer) - { - timers.put(set.getValue().getId(), (InteractionBattleBanzaiTimer) set.getValue()); - } - } - - return timers; - } - } - - public InteractionFreezeExitTile getFreezeExitTile() { for(InteractionFreezeExitTile t : this.freezeExitTile.values()) diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java index a666d706..177db674 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -1,5 +1,12 @@ package com.eu.habbo.habbohotel.rooms; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboItem; +import gnu.trove.set.hash.THashSet; + +import java.util.ArrayList; +import java.util.List; + public class RoomTile { public final short x; @@ -10,12 +17,13 @@ public class RoomTile private double stackHeight; private boolean allowStack = true; - private RoomTile previous = null; private boolean diagonally; private short gCosts; private short hCosts; + private final THashSet units; + public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack) { @@ -25,6 +33,7 @@ public class RoomTile this.stackHeight = z; this.state = state; this.setAllowStack(allowStack); + this.units = new THashSet<>(); } public RoomTile(RoomTile tile) @@ -43,6 +52,7 @@ public class RoomTile { this.allowStack = false; } + this.units = tile.units; } public double getStackHeight() @@ -199,4 +209,34 @@ public class RoomTile { return this.x == x && this.y == y; } + + public List getUnits() { + synchronized (this.units) { + return new ArrayList(this.units); + } + } + + public void addUnit(RoomUnit unit) { + synchronized (this.units) { + if (!this.units.contains(unit)) { + this.units.add(unit); + } + } + } + + public void removeUnit(RoomUnit unit) { + synchronized (this.units) { + this.units.remove(unit); + } + } + + public boolean hasUnits() { + synchronized (this.units) { + return this.units.size() > 0; + } + } + + public boolean unitIsOnFurniOnTile(RoomUnit unit, Item item) { + return (unit.getX() >= this.x && unit.getX() < this.x + item.getLength()) && (unit.getY() >= this.y && unit.getY() < this.y + item.getWidth()); + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index ebeac176..b3c50e50 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -6,8 +6,8 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionGuildGate; import com.eu.habbo.habbohotel.items.interactions.InteractionMultiHeight; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleport; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock; -import com.eu.habbo.habbohotel.pets.HorsePet; import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; @@ -21,7 +21,9 @@ import com.eu.habbo.threading.runnables.RoomUnitKick; import com.eu.habbo.util.pathfinding.Rotation; import gnu.trove.map.TMap; import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; +import java.awt.geom.RectangularShape; import java.util.Deque; import java.util.LinkedList; import java.util.Map; @@ -54,6 +56,8 @@ public class RoomUnit public int kickCount = 0; private boolean statusUpdate = false; private boolean invisible = false; + private boolean lastCycleStatus = false; + private boolean canLeaveRoomByDoor = true; private final ConcurrentHashMap status; private final THashMap cacheable; @@ -71,6 +75,7 @@ public class RoomUnit private int idleTimer; private Room room; private RoomRightLevels rightsLevel = RoomRightLevels.NONE; + private THashSet overridableTiles; public RoomUnit() { @@ -86,6 +91,7 @@ public class RoomUnit this.walkTimeOut = Emulator.getIntUnixTimestamp(); this.effectId = 0; this.isKicked = false; + this.overridableTiles = new THashSet<>(); } public void clearWalking() @@ -112,27 +118,32 @@ public class RoomUnit { try { - if (this.isTeleporting) - { - return false; - } - - Boolean isHorse = false; - Pet pet = room.getPet(this); - if(pet != null) { - if(pet instanceof HorsePet) { - isHorse = true; - if (((HorsePet) pet).getRider() != null) { - if(!((HorsePet) pet).getRider().getRoomUnit().isWalking()) { - this.status.remove(RoomUnitStatus.MOVE); - this.setCurrentLocation(((HorsePet) pet).getRider().getRoomUnit().getPreviousLocation()); - if (this.status.remove(RoomUnitStatus.MOVE) != null) this.statusUpdate = true; - - } - } + Habbo rider = null; + if(this.getRoomUnitType() == RoomUnitType.PET) { + Pet pet = room.getPet(this); + if(pet instanceof RideablePet) { + rider = ((RideablePet) pet).getRider(); } } + if(rider != null) { + // copy things from rider + if(this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatusMap().containsKey(RoomUnitStatus.MOVE)) { + this.status.remove(RoomUnitStatus.MOVE); + } + + if(rider.getRoomUnit().getCurrentLocation().x != this.getX() || rider.getRoomUnit().getCurrentLocation().y != this.getY()) { + this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().x + "," + rider.getRoomUnit().getCurrentLocation().y + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight())); + this.setPreviousLocation(rider.getRoomUnit().getPreviousLocation()); + this.setPreviousLocationZ(rider.getRoomUnit().getPreviousLocation().getStackHeight()); + this.setCurrentLocation(rider.getRoomUnit().getCurrentLocation()); + this.setZ(rider.getRoomUnit().getCurrentLocation().getStackHeight()); + } + + return this.statusUpdate; + } + + if (!this.isWalking() && !this.isKicked) { if (this.status.remove(RoomUnitStatus.MOVE) == null) @@ -168,27 +179,20 @@ public class RoomUnit canfastwalk = false; } - if (canfastwalk && this.fastWalk && this.path.size() >= 3) - { - this.path.poll(); - this.path.poll(); - } - RoomTile next = this.path.poll(); + boolean overrideChecks = next != null && this.canOverrideTile(next); if (this.path.isEmpty()) { this.sitUpdate = true; - if (next != null && room.hasHabbosAt(next.x, next.y)) + if (next != null && next.hasUnits() && !overrideChecks) { - if(!isHorse) { - return false; - } + return false; } } - Deque peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation); + Deque peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation, this); if (peekPath.size() >= 3) { path.pop(); @@ -205,6 +209,13 @@ public class RoomUnit } } + if (canfastwalk && this.fastWalk) + { + if(this.path.size() > 1) { + next = this.path.poll(); + } + } + if (next == null) return true; @@ -241,10 +252,9 @@ public class RoomUnit HabboItem item = room.getTopItemAt(next.x, next.y); - //if(!(this.path.size() == 0 && canSitNextTile)) { - if (!room.tileWalkable(next.x, next.y) && !(item instanceof InteractionTeleport)) + if (!room.tileWalkable(next.x, next.y) && !overrideChecks) { this.room = room; this.findPath(); @@ -273,7 +283,7 @@ public class RoomUnit item = lowestChair; } - if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT) + if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT && !overrideChecks) { if (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT) { @@ -284,10 +294,10 @@ public class RoomUnit double zHeight = 0.0D; - if (((habbo != null && habbo.getHabboInfo().getRiding() != null) || isHorse) && next.equals(this.goalLocation) && (next.state == RoomTileState.SIT || next.state == RoomTileState.LAY)) { + /*if (((habbo != null && habbo.getHabboInfo().getRiding() != null) || isRiding) && next.equals(this.goalLocation) && (next.state == RoomTileState.SIT || next.state == RoomTileState.LAY)) { this.status.remove(RoomUnitStatus.MOVE); return false; - } + }*/ if (habbo != null) { @@ -335,20 +345,7 @@ public class RoomUnit if (!item.getBaseItem().allowSit() && !item.getBaseItem().allowLay()) { - zHeight += item.getBaseItem().getHeight(); - - if (item instanceof InteractionMultiHeight) - { - if (item.getExtradata().length() == 0) - { - item.setExtradata("0"); - } - zHeight += Item.getCurrentHeight(item); - } - else if (item instanceof InteractionFreezeBlock) - { - zHeight -= item.getBaseItem().getHeight(); - } + zHeight += Item.getCurrentHeight(item); } } else @@ -368,14 +365,14 @@ public class RoomUnit if (ridingUnit != null) { + ridingUnit.setPreviousLocationZ(this.getZ()); this.setZ(zHeight - 1.0); ridingUnit.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.x, next.y)]); ridingUnit.setPreviousLocation(this.getCurrentLocation()); ridingUnit.setGoalLocation(this.getGoal()); ridingUnit.setStatus(RoomUnitStatus.MOVE, next.x + "," + next.y + "," + (zHeight - 1.0)); - ridingUnit.setZ(zHeight - 1.0); room.sendComposer(new RoomUserStatusComposer(ridingUnit).compose()); - + //ridingUnit.setZ(zHeight - 1.0); } } } @@ -387,7 +384,7 @@ public class RoomUnit if (habbo != null) { - if (next.x == room.getLayout().getDoorX() && next.y == room.getLayout().getDoorY() && (!room.isPublicRoom()) || (room.isPublicRoom() && Emulator.getConfig().getBoolean("hotel.room.public.doortile.kick"))) + if (this.canLeaveRoomByDoor && next.x == room.getLayout().getDoorX() && next.y == room.getLayout().getDoorY() && (!room.isPublicRoom()) || (room.isPublicRoom() && Emulator.getConfig().getBoolean("hotel.room.public.doortile.kick"))) { Emulator.getThreading().run(new RoomUnitKick(habbo, room, false), 500); } @@ -566,8 +563,8 @@ public class RoomUnit if (location != null) { this.startLocation = location; - this.previousLocation = location; - this.currentLocation = location; + setPreviousLocation(location); + setCurrentLocation(location); this.goalLocation = location; } } @@ -576,7 +573,11 @@ public class RoomUnit { if (location != null) { - this.currentLocation = location; + if(this.currentLocation != null) { + this.currentLocation.removeUnit(this); + } + this.currentLocation = location; + location.addUnit(this); } } @@ -608,9 +609,9 @@ public class RoomUnit public void findPath() { - if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y))) + if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y) || this.canOverrideTile(this.goalLocation))) { - this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation); + this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this); } } @@ -799,4 +800,37 @@ public class RoomUnit { return this.invisible; } + + public Room getRoom() { + return room; + } + + public boolean canOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + return this.overridableTiles.contains(tileIndex); + } + + public void addOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + if(!this.overridableTiles.contains(tileIndex)) { + this.overridableTiles.add(tileIndex); + } + } + + public void removeOverrideTile(RoomTile tile) { + int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1; + this.overridableTiles.remove(tileIndex); + } + + public void clearOverrideTiles() { + this.overridableTiles.clear(); + } + + public boolean canLeaveRoomByDoor() { + return canLeaveRoomByDoor; + } + + public void setCanLeaveRoomByDoor(boolean canLeaveRoomByDoor) { + this.canLeaveRoomByDoor = canLeaveRoomByDoor; + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 019b5abe..f5c3a2fb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -17,14 +17,15 @@ import com.eu.habbo.messages.outgoing.users.*; import com.eu.habbo.plugin.events.users.UserCreditsEvent; import com.eu.habbo.plugin.events.users.UserDisconnectEvent; import com.eu.habbo.plugin.events.users.UserPointsEvent; +import gnu.trove.TIntCollection; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.net.InetSocketAddress; import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class Habbo implements Runnable { @@ -40,13 +41,11 @@ public class Habbo implements Runnable private volatile boolean disconnected = false; private volatile boolean disconnecting = false; - public boolean firstVisit = false; - public Habbo(ResultSet set) { this.client = null; this.habboInfo = new HabboInfo(set); - this.habboStats = HabboStats.load(this); + this.habboStats = HabboStats.load(this.habboInfo); this.habboInventory = new HabboInventory(this); this.messenger = new Messenger(); @@ -415,6 +414,7 @@ public class Habbo implements Runnable HabboBadge badge = BadgesComponent.createBadge(code, this); this.habboInventory.getBadgesComponent().addBadge(badge); this.client.sendResponse(new AddUserBadgeComposer(badge)); + this.client.sendResponse(new AddHabboItemComposer(badge.getId(), AddHabboItemComposer.AddHabboItemCategory.BADGE)); THashMap keys = new THashMap<>(); keys.put("display", "BUBBLE"); @@ -514,4 +514,14 @@ public class Habbo implements Runnable this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo()); } } + + public Set getForbiddenClothing() { + TIntCollection clothingIDs = this.getInventory().getWardrobeComponent().getClothing(); + + return Emulator.getGameEnvironment().getCatalogManager().clothing.values().stream() + .filter(c -> !clothingIDs.contains(c.id)) + .map(c -> c.setId) + .flatMap(c -> Arrays.stream(c).boxed()) + .collect(Collectors.toSet()); + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java index 0e8a1a65..4c5cfef1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -6,7 +6,14 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.permissions.Rank; import com.eu.habbo.habbohotel.pets.HorsePet; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.RideablePet; 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.messages.outgoing.rooms.users.RoomUserStatusComposer; +import com.eu.habbo.threading.runnables.RoomUnitRidePet; +import com.eu.habbo.util.figure.FigureUtil; import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.procedure.TIntIntProcedure; @@ -14,6 +21,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class HabboInfo implements Runnable { @@ -40,7 +49,7 @@ public class HabboInfo implements Runnable private Room currentRoom; private int roomQueueId; - private HorsePet riding; + private RideablePet riding; private Class currentGame; private TIntIntHashMap currencies; @@ -52,6 +61,7 @@ public class HabboInfo implements Runnable private String photoJSON; private int webPublishTimestamp; private String machineID; + public boolean firstVisit = false; public HabboInfo(ResultSet set) { @@ -71,6 +81,8 @@ public class HabboInfo implements Runnable if (this.rank == null) { Emulator.getLogging().logErrorLine("No existing rank found with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); + Emulator.getLogging().logUserLine(this.username + " has an invalid rank with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); + this.rank = Emulator.getGameEnvironment().getPermissionsManager().getRank(1); } this.accountCreated = set.getInt("account_created"); @@ -204,7 +216,9 @@ public class HabboInfo implements Runnable return this.look; } - public void setLook(String look) { this.look = look; } + public void setLook(String look) { + this.look = look; + } public HabboGender getGender() { @@ -357,12 +371,49 @@ public class HabboInfo implements Runnable this.roomQueueId = roomQueueId; } - public HorsePet getRiding() + public RideablePet getRiding() { return this.riding; } - public void setRiding(HorsePet riding) + public void dismountPet() { + this.dismountPet(false); + } + + public void dismountPet(boolean isRemoving) { + if(this.getRiding() == null) + return; + + Habbo habbo = this.getCurrentRoom().getHabbo(this.getId()); + if(habbo == null) + return; + + RideablePet riding = this.getRiding(); + + riding.setRider(null); + riding.setTask(PetTasks.FREE); + this.setRiding(null); + + Room room = this.getCurrentRoom(); + if(room != null) + room.giveEffect(habbo, 0, -1); + + RoomUnit roomUnit = habbo.getRoomUnit(); + if(roomUnit == null) + return; + + roomUnit.setZ(riding.getRoomUnit().getZ()); + roomUnit.setPreviousLocationZ(riding.getRoomUnit().getZ()); + roomUnit.stopWalking(); + room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); + List availableTiles = isRemoving ? new ArrayList<>() : this.getCurrentRoom().getLayout().getWalkableTilesAround(roomUnit.getCurrentLocation()); + + RoomTile tile = availableTiles.isEmpty() ? roomUnit.getCurrentLocation() : availableTiles.get(0); + roomUnit.setGoalLocation(tile); + roomUnit.statusUpdate(true); + } + + public void setRiding(RideablePet riding) { this.riding = riding; } @@ -468,7 +519,7 @@ public class HabboInfo implements Runnable statement.setInt(6, Emulator.getIntUnixTimestamp()); statement.setInt(8, this.homeRoom); statement.setString(9, this.ipLogin); - statement.setInt(10, this.rank.getId()); + statement.setInt(10, this.rank != null ? this.rank.getId() : 1); statement.setString(11, this.machineID); statement.setString(12, this.username); statement.setInt(13, this.id); @@ -484,4 +535,13 @@ public class HabboInfo implements Runnable { return this.getCurrencyAmount(Emulator.getConfig().getInt("hotelview.promotional.points.type")); } + + public HabboStats getHabboStats() { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getId()); + if(habbo != null) { + return habbo.getHabboStats(); + } + + return HabboStats.load(this); + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java index 126a74f7..e3c3e9ed 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java @@ -43,6 +43,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers private int limitedSells; private boolean needsUpdate = false; private boolean needsDelete = false; + private boolean isFromGift = false; public HabboItem(ResultSet set, Item baseItem) throws SQLException { @@ -131,6 +132,12 @@ public abstract class HabboItem implements Runnable, IEventTriggers return this.id; } + public int getGiftAdjustedId() { + if (this.isFromGift) return -this.id; + + return this.id; + } + public int getUserId() { return this.userId; @@ -221,6 +228,10 @@ public abstract class HabboItem implements Runnable, IEventTriggers return this.needsUpdate; } + public boolean needsDelete() { + return needsDelete; + } + public void needsUpdate(boolean value) { this.needsUpdate = value; @@ -504,4 +515,12 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return true; } + + public boolean isFromGift() { + return isFromGift; + } + + public void setFromGift(boolean fromGift) { + isFromGift = fromGift; + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index dd783abb..6bca1549 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -110,7 +110,7 @@ public class HabboManager try(Connection connection = Emulator.getDatabase().getDataSource().getConnection(); - PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE auth_ticket LIKE ? LIMIT 1")) + PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE auth_ticket = ? LIMIT 1")) { statement.setString(1, sso); try (ResultSet set = statement.executeQuery()) @@ -119,18 +119,17 @@ public class HabboManager { habbo = new Habbo(set); - if (habbo.firstVisit) + if (habbo.getHabboInfo().firstVisit) { Emulator.getPluginManager().fireEvent(new UserRegisteredEvent(habbo)); } if (!Emulator.debugging) { - try (PreparedStatement stmt = connection.prepareStatement("UPDATE users SET auth_ticket = ? WHERE auth_ticket LIKE ? AND id = ? LIMIT 1")) + try (PreparedStatement stmt = connection.prepareStatement("UPDATE users SET auth_ticket = ? WHERE id = ? LIMIT 1")) { stmt.setString(1, ""); - stmt.setString(2, sso); - stmt.setInt(3, habbo.getHabboInfo().getId()); + stmt.setInt(2, habbo.getHabboInfo().getId()); stmt.execute(); } catch (SQLException e) { @@ -152,6 +151,13 @@ public class HabboManager return habbo; } + public HabboInfo getHabboInfo(int id) { + if(this.getHabbo(id) == null) { + return getOfflineHabboInfo(id); + } + return this.getHabbo(id).getHabboInfo(); + } + public static HabboInfo getOfflineHabboInfo(int id) { HabboInfo info = null; @@ -326,7 +332,7 @@ public class HabboManager if (!oldRank.getBadge().isEmpty()) { habbo.deleteBadge(habbo.getInventory().getBadgesComponent().getBadge(oldRank.getBadge())); - BadgesComponent.deleteBadge(userId, oldRank.getBadge()); + //BadgesComponent.deleteBadge(userId, oldRank.getBadge()); // unnecessary as Habbo.deleteBadge does this } habbo.getHabboInfo().setRank(newRank); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java index 0df200bc..058a5e11 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboStats.java @@ -27,7 +27,7 @@ public class HabboStats implements Runnable { private final int timeLoggedIn = Emulator.getIntUnixTimestamp(); - private Habbo habbo; + private HabboInfo habboInfo; public int achievementScore; public int respectPointsReceived; @@ -96,13 +96,15 @@ public class HabboStats implements Runnable public boolean allowNameChange; public boolean isPurchasingFurniture = false; + public int forumPostsCount; + public THashMap> ltdPurchaseLog = new THashMap<>(0); public long lastTradeTimestamp = Emulator.getIntUnixTimestamp(); public long lastPurchaseTimestamp = Emulator.getIntUnixTimestamp(); public long lastGiftTimestamp = Emulator.getIntUnixTimestamp(); public final TIntObjectMap offerCache = new TIntObjectHashMap<>(); - private HabboStats(ResultSet set, Habbo habbo) throws SQLException + private HabboStats(ResultSet set, HabboInfo habboInfo) throws SQLException { this.cache = new THashMap<>(0); this.achievementProgress = new THashMap<>(0); @@ -113,7 +115,7 @@ public class HabboStats implements Runnable this.secretRecipes = new TIntArrayList(0); this.calendarRewardsClaimed = new TIntArrayList(0); - this.habbo = habbo; + this.habboInfo = habboInfo; this.achievementScore = set.getInt("achievement_score"); this.respectPointsReceived = set.getInt("respects_received"); @@ -148,11 +150,12 @@ public class HabboStats implements Runnable this.muteEndTime = set.getInt("mute_end_timestamp"); this.allowNameChange = set.getString("allow_name_change").equalsIgnoreCase("1"); this.perkTrade = set.getString("perk_trade").equalsIgnoreCase("1"); + this.forumPostsCount = set.getInt("forums_post_count"); this.nuxReward = this.nux; try (PreparedStatement statement = set.getStatement().getConnection().prepareStatement("SELECT * FROM user_window_settings WHERE user_id = ? LIMIT 1")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); try (ResultSet nSet = statement.executeQuery()) { if (nSet.next()) @@ -163,18 +166,18 @@ public class HabboStats implements Runnable { try (PreparedStatement stmt = statement.getConnection().prepareStatement("INSERT INTO user_window_settings (user_id) VALUES (?)")) { - stmt.setInt(1, this.habbo.getHabboInfo().getId()); + stmt.setInt(1, this.habboInfo.getId()); stmt.executeUpdate(); } - this.navigatorWindowSettings = new HabboNavigatorWindowSettings(habbo.getHabboInfo().getId()); + this.navigatorWindowSettings = new HabboNavigatorWindowSettings(habboInfo.getId()); } } } try (PreparedStatement statement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_navigator_settings WHERE user_id = ?")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); try (ResultSet nSet = statement.executeQuery()) { while (nSet.next()) @@ -186,7 +189,7 @@ public class HabboStats implements Runnable try (PreparedStatement favoriteRoomsStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_favorite_rooms WHERE user_id = ?")) { - favoriteRoomsStatement.setInt(1, this.habbo.getHabboInfo().getId()); + favoriteRoomsStatement.setInt(1, this.habboInfo.getId()); try (ResultSet favoriteSet = favoriteRoomsStatement.executeQuery()) { while (favoriteSet.next()) @@ -199,7 +202,7 @@ public class HabboStats implements Runnable try (PreparedStatement recipesStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_recipes WHERE user_id = ?")) { - recipesStatement.setInt(1, this.habbo.getHabboInfo().getId()); + recipesStatement.setInt(1, this.habboInfo.getId()); try (ResultSet recipeSet = recipesStatement.executeQuery()) { while (recipeSet.next()) @@ -211,7 +214,7 @@ public class HabboStats implements Runnable try (PreparedStatement calendarRewardsStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM calendar_rewards_claimed WHERE user_id = ?")) { - calendarRewardsStatement.setInt(1, this.habbo.getHabboInfo().getId()); + calendarRewardsStatement.setInt(1, this.habboInfo.getId()); try (ResultSet rewardSet = calendarRewardsStatement.executeQuery()) { while (rewardSet.next()) @@ -223,7 +226,7 @@ public class HabboStats implements Runnable try (PreparedStatement ltdPurchaseLogStatement = set.getStatement().getConnection().prepareStatement("SELECT catalog_item_id, timestamp FROM catalog_items_limited WHERE user_id = ? AND timestamp > ?")) { - ltdPurchaseLogStatement.setInt(1, this.habbo.getHabboInfo().getId()); + ltdPurchaseLogStatement.setInt(1, this.habboInfo.getId()); ltdPurchaseLogStatement.setInt(2, Emulator.getIntUnixTimestamp() - 86400); try (ResultSet ltdSet = ltdPurchaseLogStatement.executeQuery()) { @@ -236,7 +239,7 @@ public class HabboStats implements Runnable try (PreparedStatement ignoredPlayersStatement = set.getStatement().getConnection().prepareStatement("SELECT target_id FROM users_ignored WHERE user_id = ?")) { - ignoredPlayersStatement.setInt(1, this.habbo.getHabboInfo().getId()); + ignoredPlayersStatement.setInt(1, this.habboInfo.getId()); try (ResultSet ignoredSet = ignoredPlayersStatement.executeQuery()) { while (ignoredSet.next()) @@ -248,7 +251,7 @@ public class HabboStats implements Runnable try (PreparedStatement loadOfferPurchaseStatement = set.getStatement().getConnection().prepareStatement("SELECT * FROM users_target_offer_purchases WHERE user_id = ?")) { - loadOfferPurchaseStatement.setInt(1, this.habbo.getHabboInfo().getId()); + loadOfferPurchaseStatement.setInt(1, this.habboInfo.getId()); try (ResultSet offerSet = loadOfferPurchaseStatement.executeQuery()) { while (offerSet.next()) @@ -264,7 +267,7 @@ public class HabboStats implements Runnable { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET achievement_score = ?, respects_received = ?, respects_given = ?, daily_respect_points = ?, block_following = ?, block_friendrequests = ?, online_time = online_time + ?, guild_id = ?, daily_pet_respect_points = ?, club_expire_timestamp = ?, login_streak = ?, rent_space_id = ?, rent_space_endtime = ?, volume_system = ?, volume_furni = ?, volume_trax = ?, block_roominvites = ?, old_chat = ?, block_camera_follow = ?, chat_color = ?, hof_points = ?, block_alerts = ?, talent_track_citizenship_level = ?, talent_track_helpers_level = ?, ignore_bots = ?, ignore_pets = ?, nux = ?, mute_end_timestamp = ?, allow_name_change = ?, perk_trade = ?, can_trade = ? WHERE user_id = ? LIMIT 1")) + try (PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET achievement_score = ?, respects_received = ?, respects_given = ?, daily_respect_points = ?, block_following = ?, block_friendrequests = ?, online_time = online_time + ?, guild_id = ?, daily_pet_respect_points = ?, club_expire_timestamp = ?, login_streak = ?, rent_space_id = ?, rent_space_endtime = ?, volume_system = ?, volume_furni = ?, volume_trax = ?, block_roominvites = ?, old_chat = ?, block_camera_follow = ?, chat_color = ?, hof_points = ?, block_alerts = ?, talent_track_citizenship_level = ?, talent_track_helpers_level = ?, ignore_bots = ?, ignore_pets = ?, nux = ?, mute_end_timestamp = ?, allow_name_change = ?, perk_trade = ?, can_trade = ?, `forums_post_count` = ? WHERE user_id = ? LIMIT 1")) { statement.setInt(1, this.achievementScore); statement.setInt(2, this.respectPointsReceived); @@ -297,7 +300,8 @@ public class HabboStats implements Runnable statement.setString(29, this.allowNameChange ? "1" : "0"); statement.setString(30, this.perkTrade ? "1" : "0"); statement.setString(31, this.allowTrade ? "1" : "0"); - statement.setInt(32, this.habbo.getHabboInfo().getId()); + statement.setInt(32, this.forumPostsCount); + statement.setInt(33, this.habboInfo.getId()); statement.executeUpdate(); } @@ -308,7 +312,7 @@ public class HabboStats implements Runnable statement.setInt(3, this.navigatorWindowSettings.width); statement.setInt(4, this.navigatorWindowSettings.height); statement.setString(5, this.navigatorWindowSettings.openSearches ? "1" : "0"); - statement.setInt(6, this.habbo.getHabboInfo().getId()); + statement.setInt(6, this.habboInfo.getId()); statement.executeUpdate(); } @@ -323,7 +327,7 @@ public class HabboStats implements Runnable statement.setInt(1, purchase.getState()); statement.setInt(2, purchase.getAmount()); statement.setInt(3, purchase.getLastPurchaseTimestamp()); - statement.setInt(4, this.habbo.getHabboInfo().getId()); + statement.setInt(4, this.habboInfo.getId()); statement.setInt(5, purchase.getOfferId()); statement.execute(); } @@ -341,17 +345,17 @@ public class HabboStats implements Runnable public void dispose() { this.run(); - this.habbo = null; + this.habboInfo = null; this.recentPurchases.clear(); } - private static HabboStats createNewStats(Habbo habbo) + private static HabboStats createNewStats(HabboInfo habboInfo) { - habbo.firstVisit = true; + habboInfo.firstVisit = true; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_settings (user_id) VALUES (?)")) { - statement.setInt(1, habbo.getHabboInfo().getId()); + statement.setInt(1, habboInfo.getId()); statement.executeUpdate(); } catch (SQLException e) @@ -359,27 +363,27 @@ public class HabboStats implements Runnable Emulator.getLogging().logSQLException(e); } - return load(habbo); + return load(habboInfo); } - public static HabboStats load(Habbo habbo) + public static HabboStats load(HabboInfo habboInfo) { HabboStats stats = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { try(PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_settings WHERE user_id = ? LIMIT 1")) { - statement.setInt(1, habbo.getHabboInfo().getId()); + statement.setInt(1, habboInfo.getId()); try (ResultSet set = statement.executeQuery()) { set.first(); if (set.getRow() != 0) { - stats = new HabboStats(set, habbo); + stats = new HabboStats(set, habboInfo); } else { - stats = createNewStats(habbo); + stats = createNewStats(habboInfo); } } } @@ -388,7 +392,7 @@ public class HabboStats implements Runnable { try (PreparedStatement statement = connection.prepareStatement("SELECT guild_id FROM guilds_members WHERE user_id = ? AND level_id < 3 LIMIT 100")) { - statement.setInt(1, habbo.getHabboInfo().getId()); + statement.setInt(1, habboInfo.getId()); try (ResultSet set = statement.executeQuery()) { @@ -405,7 +409,7 @@ public class HabboStats implements Runnable try (PreparedStatement statement = connection.prepareStatement("SELECT room_id FROM room_votes WHERE user_id = ?")) { - statement.setInt(1, habbo.getHabboInfo().getId()); + statement.setInt(1, habboInfo.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) @@ -417,7 +421,7 @@ public class HabboStats implements Runnable try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM users_achievements WHERE user_id = ?")) { - statement.setInt(1, habbo.getHabboInfo().getId()); + statement.setInt(1, habboInfo.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) @@ -566,7 +570,7 @@ public class HabboStats implements Runnable try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_favorite_rooms (user_id, room_id) VALUES (?, ?)")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); statement.setInt(2, roomId); statement.execute(); } @@ -585,7 +589,7 @@ public class HabboStats implements Runnable { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_favorite_rooms WHERE user_id = ? AND room_id = ? LIMIT 1")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); statement.setInt(2, roomId); statement.execute(); } @@ -618,7 +622,7 @@ public class HabboStats implements Runnable try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_recipes (user_id, recipe) VALUES (?, ?)")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); statement.setInt(2, id); statement.execute(); } @@ -723,7 +727,7 @@ public class HabboStats implements Runnable try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_ignored (user_id, target_id) VALUES (?, ?)")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); statement.setInt(2, userId); statement.execute(); } @@ -743,7 +747,7 @@ public class HabboStats implements Runnable try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_ignored WHERE user_id = ? AND target_id = ?")) { - statement.setInt(1, this.habbo.getHabboInfo().getId()); + statement.setInt(1, this.habboInfo.getId()); statement.setInt(2, userId); statement.execute(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java index a66ee949..25e58d0e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java @@ -41,9 +41,9 @@ public class BadgesComponent { boolean delete = true; - for (Rank rank : Emulator.getGameEnvironment().getPermissionsManager().getRanks(badge.getCode())) + for (Rank rank : Emulator.getGameEnvironment().getPermissionsManager().getRanksByBadgeCode(badge.getCode())) { - if (rank.getId() == habbo.getHabboInfo().getId()) + if (rank.getId() == habbo.getHabboInfo().getRank().getId()) { delete = false; break; diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java index f38e543c..d83efed7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java @@ -117,7 +117,7 @@ public class ItemsComponent public HabboItem getHabboItem(int itemId) { - return this.items.get(itemId); + return this.items.get(Math.abs(itemId)); } public HabboItem getAndRemoveHabboItem(final Item item) diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index a25016da..dfb6bd2a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -217,7 +217,7 @@ public class WiredHandler private static boolean triggerEffect(InteractionWiredEffect effect, RoomUnit roomUnit, Room room, Object[] stuff, long millis) { boolean executed = false; - if (effect.canExecute(millis)) + if (effect != null && effect.canExecute(millis)) { executed = true; if (!effect.requiresTriggeringUser() || (roomUnit != null && effect.requiresTriggeringUser())) diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 7ebcfb5d..163826c1 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -549,9 +549,9 @@ public class PacketManager this.registerHandler(Incoming.PetPickupEvent, PetPickupEvent.class); this.registerHandler(Incoming.ScratchPetEvent, ScratchPetEvent.class); this.registerHandler(Incoming.RequestPetTrainingPanelEvent, RequestPetTrainingPanelEvent.class); - this.registerHandler(Incoming.HorseUseItemEvent, HorseUseItemEvent.class); - this.registerHandler(Incoming.HorseRideSettingsEvent, HorseRideSettingsEvent.class); - this.registerHandler(Incoming.HorseRideEvent, HorseRideEvent.class); + this.registerHandler(Incoming.HorseUseItemEvent, PetUseItemEvent.class); + this.registerHandler(Incoming.HorseRideSettingsEvent, PetRideSettingsEvent.class); + this.registerHandler(Incoming.HorseRideEvent, PetRideEvent.class); this.registerHandler(Incoming.ToggleMonsterplantBreedableEvent, ToggleMonsterplantBreedableEvent.class); this.registerHandler(Incoming.CompostMonsterplantEvent, CompostMonsterplantEvent.class); this.registerHandler(Incoming.BreedMonsterplantsEvent, BreedMonsterplantsEvent.class); diff --git a/src/main/java/com/eu/habbo/messages/PacketManager_1006.java b/src/main/java/com/eu/habbo/messages/PacketManager_1006.java index 41b0ea54..1df004dd 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager_1006.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager_1006.java @@ -396,9 +396,9 @@ public class PacketManager_1006 this.registerHandler(Incoming.PetPickupEvent, PetPickupEvent.class); this.registerHandler(Incoming.ScratchPetEvent, ScratchPetEvent.class); this.registerHandler(Incoming.RequestPetTrainingPanelEvent, RequestPetTrainingPanelEvent.class); - this.registerHandler(Incoming.HorseUseItemEvent, HorseUseItemEvent.class); - this.registerHandler(Incoming.HorseRideSettingsEvent, HorseRideSettingsEvent.class); - this.registerHandler(Incoming.HorseRideEvent, HorseRideEvent.class); + this.registerHandler(Incoming.HorseUseItemEvent, PetUseItemEvent.class); + this.registerHandler(Incoming.HorseRideSettingsEvent, PetRideSettingsEvent.class); + this.registerHandler(Incoming.HorseRideEvent, PetRideEvent.class); } void registerWired() diff --git a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertCommandEvent.java b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertCommandEvent.java index 838c4f82..d7456e25 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertCommandEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertCommandEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.ambassadors; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; @@ -13,7 +14,7 @@ public class AmbassadorAlertCommandEvent extends MessageHandler public void handle() throws Exception { if(!this.client.getHabbo().hasPermission("acc_ambassador")) { - Emulator.getGameEnvironment().getModToolManager().quickTicket(client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", client.getHabbo().getHabboInfo().getUsername()).replace("%message%", "${notification.ambassador.alert.warning.message}")); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", client.getHabbo().getHabboInfo().getUsername()).replace("%message%", "${notification.ambassador.alert.warning.message}")); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/RequestCatalogPageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/RequestCatalogPageEvent.java index 07dcaa51..05c4a9ee 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/RequestCatalogPageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/RequestCatalogPageEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.catalog; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.catalog.CatalogPage; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.CatalogPageComposer; @@ -27,7 +28,7 @@ public class RequestCatalogPageEvent extends MessageHandler { if(!page.isVisible()) { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.catalog.page").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%pagename%", page.getCaption())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.catalog.page").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%pagename%", page.getCaption())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/SellItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/SellItemEvent.java index 02a10122..0ef2fd45 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/SellItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/SellItemEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.catalog.marketplace; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.catalog.marketplace.MarketPlace; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer; @@ -30,7 +31,7 @@ public class SellItemEvent extends MessageHandler if (!item.getBaseItem().allowMarketplace()) { String message = Emulator.getTexts().getValue("scripter.warning.marketplace.forbidden").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%itemname%", item.getBaseItem().getName()).replace("%credits%", credits + ""); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); this.client.sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); return; @@ -39,7 +40,7 @@ public class SellItemEvent extends MessageHandler if(credits < 0) { String message = Emulator.getTexts().getValue("scripter.warning.marketplace.negative").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%itemname%", item.getBaseItem().getName()).replace("%credits%", credits + ""); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); this.client.sendResponse(new AlertPurchaseFailedComposer(AlertPurchaseFailedComposer.SERVER_ERROR)); return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java index ef8af017..59cf6391 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java @@ -50,8 +50,8 @@ public class RecycleEvent extends MessageHandler for (HabboItem item : items) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId())); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } else diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftItemEvent.java index 9c900a5c..eb0bc703 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftItemEvent.java @@ -74,7 +74,7 @@ public class CraftingCraftItemEvent extends MessageHandler @Override public boolean execute(HabboItem object) { - CraftingCraftItemEvent.this.client.sendResponse(new RemoveHabboItemComposer(object.getId())); + CraftingCraftItemEvent.this.client.sendResponse(new RemoveHabboItemComposer(object.getGiftAdjustedId())); return true; } }); diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftSecretEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftSecretEvent.java index e40449c0..d3fd19ff 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftSecretEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftingCraftSecretEvent.java @@ -93,8 +93,8 @@ public class CraftingCraftSecretEvent extends MessageHandler for (HabboItem item : habboItems) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId())); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } this.client.sendResponse(new InventoryRefreshComposer()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/FriendPrivateMessageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/FriendPrivateMessageEvent.java index b4ca9fb6..fdd95137 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/FriendPrivateMessageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/FriendPrivateMessageEvent.java @@ -30,40 +30,14 @@ public class FriendPrivateMessageEvent extends MessageHandler } this.client.getHabbo().getHabboStats().lastChat = millis; - if(userId == Emulator.publicChatBuddy.getId()) - { - if(message.startsWith(":")) - { - CommandHandler.handleCommand(this.client, message); - return; - } - Emulator.getGameServer().getGameClientManager().sendBroadcastResponse(new FriendChatMessageComposer(new Message(this.client.getHabbo().getHabboInfo().getId(), -1, message)).compose(), "acc_staff_chat", this.client); - return; - } - MessengerBuddy buddy = this.client.getHabbo().getMessenger().getFriend(userId); if (buddy == null) - { return; - } UserFriendChatEvent event = new UserFriendChatEvent(this.client.getHabbo(), buddy, message); if(Emulator.getPluginManager().fireEvent(event).isCancelled()) return; - Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(userId); - - if(habbo == null) - return; - - Message chatMessage = new Message(this.client.getHabbo().getHabboInfo().getId(), userId, event.message); - Emulator.getThreading().run(chatMessage); - - if (WordFilter.ENABLED_FRIENDCHAT) - { - chatMessage.setMessage(Emulator.getGameEnvironment().getWordFilter().filter(chatMessage.getMessage(), this.client.getHabbo())); - } - - habbo.getClient().sendResponse(new FriendChatMessageComposer(chatMessage)); + buddy.onMessageReceived(this.client.getHabbo(), message); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildChangeSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildChangeSettingsEvent.java index 9f3e573a..920b72fd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildChangeSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildChangeSettingsEvent.java @@ -25,7 +25,7 @@ public class GuildChangeSettingsEvent extends MessageHandler if (room == null) return; - GuildChangedSettingsEvent settingsEvent = new GuildChangedSettingsEvent(guild, this.packet.readInt(), this.packet.readInt()); + GuildChangedSettingsEvent settingsEvent = new GuildChangedSettingsEvent(guild, this.packet.readInt(), this.packet.readInt() == 0); Emulator.getPluginManager().fireEvent(settingsEvent); if (settingsEvent.isCancelled()) diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildSetFavoriteEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildSetFavoriteEvent.java index a173a6aa..5eae7935 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildSetFavoriteEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildSetFavoriteEvent.java @@ -29,11 +29,10 @@ public class GuildSetFavoriteEvent extends MessageHandler if(this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - if(guild != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new GuildFavoriteRoomUserUpdateComposer(this.client.getHabbo().getRoomUnit(), guild).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUsersAddGuildBadgeComposer(guild).compose()); + this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new GuildFavoriteRoomUserUpdateComposer(this.client.getHabbo().getRoomUnit(), guild).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildBuyEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildBuyEvent.java index f341e9e6..fbdd6c94 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildBuyEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildBuyEvent.java @@ -2,12 +2,14 @@ package com.eu.habbo.messages.incoming.guilds; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.AlertPurchaseFailedComposer; import com.eu.habbo.messages.outgoing.catalog.PurchaseOKComposer; import com.eu.habbo.messages.outgoing.guilds.GuildBoughtComposer; +import com.eu.habbo.messages.outgoing.guilds.GuildEditFailComposer; import com.eu.habbo.messages.outgoing.guilds.GuildInfoComposer; import com.eu.habbo.plugin.events.guilds.GuildPurchasedEvent; @@ -30,6 +32,11 @@ public class RequestGuildBuyEvent extends MessageHandler } } + if(Emulator.getConfig().getBoolean("catalog.guild.hc_required", true) && this.client.getHabbo().getHabboStats().getClubExpireTimestamp() < Emulator.getIntUnixTimestamp()) { + this.client.sendResponse(new GuildEditFailComposer(GuildEditFailComposer.HC_REQUIRED)); + return; + } + String name = this.packet.readString(); String description = this.packet.readString(); @@ -39,6 +46,11 @@ public class RequestGuildBuyEvent extends MessageHandler if(r != null) { + if(r.hasGuild()) { + this.client.sendResponse(new GuildEditFailComposer(GuildEditFailComposer.ROOM_ALREADY_IN_USE)); + return; + } + if(r.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) { if (r.getGuildId() == 0) @@ -98,7 +110,7 @@ public class RequestGuildBuyEvent extends MessageHandler else { String message = Emulator.getTexts().getValue("scripter.warning.guild.buy.owner").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", r.getName().replace("%owner%", r.getOwnerName())); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumDataEvent.java index f39518c8..a8475d73 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumDataEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer; @@ -12,11 +12,11 @@ public class GuildForumDataEvent extends MessageHandler { int guildId = packet.readInt(); - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - if(forum == null) + if(guild == null) return; - this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo())); + this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo())); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumListEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumListEvent.java index 1085c051..e72e2e14 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumListEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumListEvent.java @@ -1,26 +1,96 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumListComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; +import gnu.trove.set.hash.THashSet; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; public class GuildForumListEvent extends MessageHandler { @Override public void handle() throws Exception { int mode = this.packet.readInt(); - int page = this.packet.readInt(); + int offset = this.packet.readInt(); int amount = this.packet.readInt(); + THashSet guilds = null; switch (mode) { - case 0: - this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getAllForumsByVisited(), this.client.getHabbo(), mode, page)); + case 0: // most active + guilds = getPopularForums(); break; - case 1: - this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getAllForumsByActive(), this.client.getHabbo(), mode, page)); + + case 1: // most viewed + guilds = getPopularForums(); break; - case 2: - this.client.sendResponse(new GuildForumListComposer(Emulator.getGameEnvironment().getGuildForumManager().getGuildForums(this.client.getHabbo()), this.client.getHabbo(), mode, page)); + + case 2: // my groups + guilds = getMyForums(this.client.getHabbo().getHabboInfo().getId()); break; } + + if(guilds != null) { + this.client.sendResponse(new GuildForumListComposer(guilds, this.client.getHabbo(), mode, offset)); + } + } + + private THashSet getPopularForums() { + THashSet guilds = new THashSet(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT `guilds`.`id`, SUM(`guilds_forums_threads`.`posts_count`) AS `post_count` " + + "FROM `guilds_forums_threads` " + + "LEFT JOIN `guilds` ON `guilds`.`id` = `guilds_forums_threads`.`guild_id` " + + "GROUP BY `guilds`.`id` " + + "ORDER BY `post_count` DESC LIMIT 100")) + { + ResultSet set = statement.executeQuery(); + + while(set.next()) { + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(set.getInt("id")); + + if(guild != null) { + guilds.add(guild); + } + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + this.client.sendResponse(new ConnectionErrorComposer(500)); + } + + return guilds; + } + + private THashSet getMyForums(int userId) { + THashSet guilds = new THashSet(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT `guilds`.`id` FROM `guilds_members` " + + "LEFT JOIN `guilds` ON `guilds`.`id` = `guilds_members`.`guild_id` " + + "WHERE `guilds_members`.`user_id` = ? AND `guilds`.`forum` = '1'")) + { + statement.setInt(1, userId); + ResultSet set = statement.executeQuery(); + + while(set.next()) { + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(set.getInt("id")); + + if(guild != null) { + guilds.add(guild); + } + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + this.client.sendResponse(new ConnectionErrorComposer(500)); + } + + return guilds; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateMessageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateMessageEvent.java index 60de1bfb..14e3106c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateMessageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateMessageEvent.java @@ -4,13 +4,14 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildMember; import com.eu.habbo.habbohotel.guilds.GuildRank; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.guilds.forums.PostUpdateMessageComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumModerateMessageEvent extends MessageHandler { @@ -22,43 +23,52 @@ public class GuildForumModerateMessageEvent extends MessageHandler { int state = packet.readInt(); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + ForumThread thread = ForumThread.getById(threadId); + + if(guild == null || thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } + + ForumThreadComment comment = thread.getCommentById(messageId); + if(comment == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q"); - final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); - boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()); - if (guild == null || (!isAdmin && !isStaff)) + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); + if(member == null) { + this.client.sendResponse(new ConnectionErrorComposer(401)); return; - - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); - GuildForumThread thread = forum.getThread(threadId); - - if (thread != null) { - - if(messageId >= 0) { - Emulator.getLogging().logDebugLine("Forum message ID - " + messageId); - GuildForumComment comment = thread.getCommentById(messageId); - comment.setState(GuildForum.ThreadState.fromValue(state)); - comment.setAdminId(this.client.getHabbo().getHabboInfo().getId()); - comment.setAdminName(this.client.getHabbo().getHabboInfo().getUsername()); - - Emulator.getThreading().run(comment); - - this.client.sendResponse(new PostUpdateMessageComposer(guildId, threadId, comment)); - } - - switch (state) { - case 10: - case 20: - this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_HIDDEN.key).compose()); - break; - case 1: - this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_RESTORED.key).compose()); - break; - } - - } else { - } + + boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type); + + if (!isAdmin && !isStaff) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + if(state == ForumThreadState.HIDDEN_BY_STAFF.getStateId() && !isStaff) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + comment.setState(ForumThreadState.fromValue(state)); + comment.setAdminId(this.client.getHabbo().getHabboInfo().getId()); + this.client.sendResponse(new PostUpdateMessageComposer(guild.getId(), thread.getThreadId(), comment)); + + switch (state) { + case 10: + case 20: + this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_HIDDEN.key).compose()); + break; + case 1: + this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_MESSAGE_RESTORED.key).compose()); + break; + } + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateThreadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateThreadEvent.java index 20a4cbfc..39ed968a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateThreadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumModerateThreadEvent.java @@ -4,12 +4,13 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildMember; import com.eu.habbo.habbohotel.guilds.GuildRank; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadMessagesComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumModerateThreadEvent extends MessageHandler { @@ -20,19 +21,35 @@ public class GuildForumModerateThreadEvent extends MessageHandler { int state = packet.readInt(); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + ForumThread thread = ForumThread.getById(threadId); + + if(guild == null || thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q"); - final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); - boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()); - if (guild == null || (!isAdmin && !isStaff)) + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); + if(member == null) { + this.client.sendResponse(new ConnectionErrorComposer(401)); return; + } - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); - GuildForumThread thread = forum.getThread(threadId); - thread.setState(GuildForum.ThreadState.fromValue(state)); + boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type); + + if (!isAdmin && !isStaff) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + if(state == ForumThreadState.HIDDEN_BY_STAFF.getStateId() && !isStaff) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + thread.setState(ForumThreadState.fromValue(state)); thread.setAdminId(this.client.getHabbo().getHabboInfo().getId()); - thread.setAdminName(this.client.getHabbo().getHabboInfo().getUsername()); switch (state) { case 10: @@ -44,8 +61,6 @@ public class GuildForumModerateThreadEvent extends MessageHandler { break; } - Emulator.getThreading().run(thread); - this.client.sendResponse(new GuildForumThreadMessagesComposer(thread)); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumPostThreadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumPostThreadEvent.java index 0b90612d..710efe9e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumPostThreadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumPostThreadEvent.java @@ -4,12 +4,12 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildMember; import com.eu.habbo.habbohotel.guilds.GuildRank; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumAddCommentComposer; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadMessagesComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumPostThreadEvent extends MessageHandler { @@ -20,49 +20,74 @@ public class GuildForumPostThreadEvent extends MessageHandler { String subject = this.packet.readString(); String message = this.packet.readString(); - final GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); - final Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - final GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + + if(guild == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } + + if (message.length() < 10 || message.length() > 4000 || (threadId == 0 && (subject.length() < 10 || subject.length() > 120))) { + this.client.sendResponse(new ConnectionErrorComposer(400)); + return; + } + boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q"); - final GuildForumThread thread; + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); - if (forum != null) { - if (message.length() < 10 || message.length() > 4000) return; + ForumThread thread = ForumThread.getById(threadId); - if (threadId == 0) { - if ((guild.canPostThreads().state == 0) - || (guild.canPostThreads().state == 1 && member != null) - || (guild.canPostThreads().state == 2 && member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN)) - || (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) - || isStaff) { - thread = forum.createThread(this.client.getHabbo(), subject, message); - - GuildForumComment comment = new GuildForumComment(guildId, threadId, this.client.getHabbo().getHabboInfo().getId(), - this.client.getHabbo().getHabboInfo().getUsername(), this.client.getHabbo().getHabboInfo().getLook(), message); - - thread.addComment(comment); - - this.client.sendResponse(new GuildForumThreadMessagesComposer(thread)); - } - } else { - if ((guild.canPostThreads().state == 0) - || (guild.canPostThreads().state == 1 && member != null) - || (guild.canPostThreads().state == 2 && member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN)) - || (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) - || isStaff) { - thread = forum.getThread(threadId); - - if(thread == null) - return; - - GuildForumComment comment = thread.addComment(this.client.getHabbo(), message); - - if (comment != null) { - this.client.sendResponse(new GuildForumAddCommentComposer(comment)); - } - } + if(threadId == 0) { + if (!((guild.canPostThreads().state == 0) + || (guild.canPostThreads().state == 1 && member != null) + || (guild.canPostThreads().state == 2 && member != null && (member.getRank().type < GuildRank.MEMBER.type)) + || (guild.canPostThreads().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) + || isStaff)) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; } + + + thread = ForumThread.create(guild, this.client.getHabbo(), subject, message); + + if (thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(500)); + return; + } + + this.client.getHabbo().getHabboStats().forumPostsCount += 1; + thread.setPostsCount(thread.getPostsCount() + 1); + this.client.sendResponse(new GuildForumThreadMessagesComposer(thread)); + return; + } + + if(thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } + + + if (!((guild.canPostMessages().state == 0) + || (guild.canPostMessages().state == 1 && member != null) + || (guild.canPostMessages().state == 2 && member != null && (member.getRank().type < GuildRank.MEMBER.type)) + || (guild.canPostMessages().state == 3 && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) + || isStaff)) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + ForumThreadComment comment = ForumThreadComment.create(thread, this.client.getHabbo(), message); + + if(comment != null) { + thread.addComment(comment); + thread.setUpdatedAt(Emulator.getIntUnixTimestamp()); + this.client.getHabbo().getHabboStats().forumPostsCount += 1; + thread.setPostsCount(thread.getPostsCount() + 1); + this.client.sendResponse(new GuildForumAddCommentComposer(comment)); + } + else { + this.client.sendResponse(new ConnectionErrorComposer(500)); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadUpdateEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadUpdateEvent.java index 10a06437..30e34275 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadUpdateEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadUpdateEvent.java @@ -1,17 +1,52 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.guilds.GuildMember; +import com.eu.habbo.habbohotel.guilds.GuildRank; +import com.eu.habbo.habbohotel.guilds.SettingsState; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadsComposer; import com.eu.habbo.messages.outgoing.guilds.forums.ThreadUpdatedMessageComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumThreadUpdateEvent extends MessageHandler { @Override public void handle() throws Exception { - int groupId = this.packet.readInt(); + int guildId = this.packet.readInt(); int threadId = this.packet.readInt(); boolean isPinned = this.packet.readBoolean(); boolean isLocked = this.packet.readBoolean(); - this.client.sendResponse(new ThreadUpdatedMessageComposer(Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(groupId), threadId, this.client.getHabbo(), isPinned, isLocked)); + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + ForumThread thread = ForumThread.getById(threadId); + + if(guild == null || thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); + return; + } + + boolean isStaff = this.client.getHabbo().hasPermission("acc_modtool_ticket_q"); + + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); + if(member == null) { + this.client.sendResponse(new ConnectionErrorComposer(401)); + return; + } + + boolean isAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().type < GuildRank.MEMBER.type); + + if ((guild.canModForum() == SettingsState.OWNER && guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() && !isStaff) || (guild.canModForum() == SettingsState.ADMINS && !isAdmin && !isStaff)) { + this.client.sendResponse(new ConnectionErrorComposer(403)); + return; + } + + this.client.sendResponse(new ThreadUpdatedMessageComposer(guild, thread, this.client.getHabbo(), isPinned, isLocked)); + + if(isPinned) { + this.client.sendResponse(new GuildForumThreadsComposer(guild, 0)); + } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsEvent.java index cbace8e5..b2ac9fd3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsEvent.java @@ -1,27 +1,28 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumThreadsComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumThreadsEvent extends MessageHandler { @Override public void handle() throws Exception { - int groupdId = packet.readInt(); + int guildId = packet.readInt(); int index = packet.readInt(); - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(groupdId); + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - if(forum == null) + if(guild == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); return; + } - this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo())); - this.client.sendResponse(new GuildForumThreadsComposer(forum, index)); - - //TODO read guild id; + this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo())); + this.client.sendResponse(new GuildForumThreadsComposer(guild, index)); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsMessagesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsMessagesEvent.java index 70f4b609..a56a33f5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsMessagesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumThreadsMessagesEvent.java @@ -2,12 +2,13 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadState; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumCommentsComposer; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumThreadsMessagesEvent extends MessageHandler { @@ -16,29 +17,26 @@ public class GuildForumThreadsMessagesEvent extends MessageHandler { int guildId = packet.readInt(); int threadId = packet.readInt(); - int index = packet.readInt(); //40 - int limit = packet.readInt(); //20 + int index = packet.readInt(); // 40 + int limit = packet.readInt(); // 20 Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + ForumThread thread = ForumThread.getById(threadId); - if(guild == null) + if(guild == null || thread == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); return; - - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); - - if(forum == null) - return; - - GuildForumThread thread = forum.getThread(threadId); - - if (thread.getState() == GuildForum.ThreadState.HIDDEN_BY_ADMIN && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) - { - this.client.sendResponse(new BubbleAlertComposer("forums.error.access_denied")); - } else - { - this.client.sendResponse(new GuildForumCommentsComposer(guildId, threadId, index, thread.getComments(index, limit))); } - this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo())); + if ((thread.getState() == ForumThreadState.HIDDEN_BY_ADMIN || thread.getState() == ForumThreadState.HIDDEN_BY_STAFF) && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) + { + this.client.sendResponse(new BubbleAlertComposer("oldforums.error.access_denied")); + } + else + { + this.client.sendResponse(new GuildForumCommentsComposer(guildId, threadId, index, thread.getComments(limit, index))); + } + + this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo())); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumUpdateSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumUpdateSettingsEvent.java index 2a5e951a..8396abe9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumUpdateSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GuildForumUpdateSettingsEvent.java @@ -3,11 +3,11 @@ package com.eu.habbo.messages.incoming.guilds.forums; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.SettingsState; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.guilds.forums.GuildForumDataComposer; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; public class GuildForumUpdateSettingsEvent extends MessageHandler { @@ -22,13 +22,15 @@ public class GuildForumUpdateSettingsEvent extends MessageHandler Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - if(guild == null || guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) + if(guild == null) { + this.client.sendResponse(new ConnectionErrorComposer(404)); return; + } - GuildForum forum = Emulator.getGameEnvironment().getGuildForumManager().getGuildForum(guildId); - - if(forum == null) + if(guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) { + this.client.sendResponse(new ConnectionErrorComposer(403)); return; + } guild.setReadForum(SettingsState.fromValue(canRead)); guild.setPostMessages(SettingsState.fromValue(postMessages)); @@ -41,6 +43,6 @@ public class GuildForumUpdateSettingsEvent extends MessageHandler this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FORUMS_FORUM_SETTINGS_UPDATED.key).compose()); - this.client.sendResponse(new GuildForumDataComposer(forum, this.client.getHabbo())); + this.client.sendResponse(new GuildForumDataComposer(guild, this.client.getHabbo())); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolAlertEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolAlertEvent.java index 26097f2f..7233c375 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolAlertEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolAlertEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; @@ -20,7 +21,7 @@ public class ModToolAlertEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.kick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.kick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolChangeRoomSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolChangeRoomSettingsEvent.java index feb7fa70..d26915a8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolChangeRoomSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolChangeRoomSettingsEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -25,7 +26,7 @@ public class ModToolChangeRoomSettingsEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.roomsettings").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.roomsettings").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolCloseTicketEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolCloseTicketEvent.java index 95043863..b821b712 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolCloseTicketEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolCloseTicketEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolIssue; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; @@ -41,7 +42,7 @@ public class ModToolCloseTicketEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.ticket.close").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ticket.close").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolPickTicketEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolPickTicketEvent.java index 60d80eb6..44f75d01 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolPickTicketEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolPickTicketEvent.java @@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolIssue; import com.eu.habbo.habbohotel.modtool.ModToolTicketState; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer; @@ -39,7 +40,7 @@ public class ModToolPickTicketEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.ticket.pick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ticket.pick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolReleaseTicketEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolReleaseTicketEvent.java index d65d7812..cd1ab13b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolReleaseTicketEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolReleaseTicketEvent.java @@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolIssue; import com.eu.habbo.habbohotel.modtool.ModToolTicketState; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.messages.incoming.MessageHandler; @@ -38,7 +39,7 @@ public class ModToolReleaseTicketEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.ticket.release").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ticket.release").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java index 75d09c52..829778b5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestIssueChatlogEvent.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolChatLog; import com.eu.habbo.habbohotel.modtool.ModToolIssue; import com.eu.habbo.habbohotel.modtool.ModToolTicketType; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -53,7 +54,7 @@ public class ModToolRequestIssueChatlogEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomChatlogEvent.java index e3864853..27fb04c4 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomChatlogEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -21,7 +22,7 @@ public class ModToolRequestRoomChatlogEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomInfoEvent.java index d0c38ad7..bc2a04ad 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomInfoEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -25,7 +26,7 @@ public class ModToolRequestRoomInfoEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.roominfo").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.roominfo").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java index 688e4baa..233425b2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; @@ -30,7 +31,7 @@ public class ModToolRequestRoomUserChatlogEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserChatlogEvent.java index 943b553a..3a9b18b3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserChatlogEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; @@ -20,7 +21,7 @@ public class ModToolRequestUserChatlogEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserInfoEvent.java index 234562b9..9249e1b3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestUserInfoEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolManager; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.messages.incoming.MessageHandler; @@ -16,7 +17,7 @@ public class ModToolRequestUserInfoEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.userinfo").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.userinfo").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRoomAlertEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRoomAlertEvent.java index b56ddf10..8e81d681 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRoomAlertEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRoomAlertEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -22,7 +23,7 @@ public class ModToolRoomAlertEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.roomalert").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.roomalert").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java index 07c7f969..04e03871 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolBanType; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.messages.incoming.MessageHandler; @@ -44,7 +45,7 @@ public class ModToolSanctionBanEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.ban").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ban").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java index 92eafdd7..06acd1db 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; @@ -20,7 +21,7 @@ public class ModToolWarnEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.modtools.kick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.kick").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java index 92de0d7e..00438bbc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestDeleteRoomEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.navigator; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.plugin.events.navigator.NavigatorRoomDeletedEvent; @@ -90,7 +91,7 @@ public class RequestDeleteRoomEvent extends MessageHandler else { String message = Emulator.getTexts().getValue("scripter.warning.room.delete").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", room.getName()).replace("%roomowner%", room.getOwnerName()); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestNewNavigatorRoomsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestNewNavigatorRoomsEvent.java index 69457e82..9709bfe0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestNewNavigatorRoomsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/RequestNewNavigatorRoomsEvent.java @@ -1,13 +1,13 @@ package com.eu.habbo.messages.incoming.navigator; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.navigation.NavigatorFilter; -import com.eu.habbo.habbohotel.navigation.NavigatorFilterField; -import com.eu.habbo.habbohotel.navigation.SearchResultList; +import com.eu.habbo.habbohotel.navigation.*; +import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomCategory; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.navigator.NewNavigatorSearchResultsComposer; +import gnu.trove.map.hash.THashMap; import java.util.*; @@ -58,6 +58,11 @@ public class RequestNewNavigatorRoomsEvent extends MessageHandler List resultLists = filter.getResult(this.client.getHabbo()); Collections.sort(resultLists); + + if(!query.isEmpty()) { + resultLists = toQueryResults(resultLists); + } + this.client.sendResponse(new NewNavigatorSearchResultsComposer(view, query, resultLists)); return; } @@ -70,6 +75,19 @@ public class RequestNewNavigatorRoomsEvent extends MessageHandler if (filter == null) return; + try + { + List resultLists = new ArrayList<>(filter.getResult(this.client.getHabbo(), field, part, category != null ? category.getId() : -1)); + filter.filter(field.field, part, resultLists); + resultLists = toQueryResults(resultLists); + this.client.sendResponse(new NewNavigatorSearchResultsComposer(view, query, resultLists)); + } + catch (Exception e) + { + Emulator.getLogging().logErrorLine(e); + } + + /* try { @@ -83,6 +101,24 @@ public class RequestNewNavigatorRoomsEvent extends MessageHandler { Emulator.getLogging().logErrorLine(e); } + */ + } + + private ArrayList toQueryResults(List resultLists) { + ArrayList nList = new ArrayList<>(); + THashMap searchRooms = new THashMap<>(); + + for(SearchResultList li : resultLists) + { + for(Room room : li.rooms) + { + searchRooms.put(room.getId(), room); + } + } + + SearchResultList list = new SearchResultList(0, "query", "", SearchAction.NONE, ListMode.LIST, DisplayMode.VISIBLE, new ArrayList(searchRooms.values()), true, this.client.getHabbo().hasPermission("acc_enter_anyroom") || this.client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER), DisplayOrder.ACTIVITY, -1); + nList.add(list); + return nList; } private void filter(List resultLists, NavigatorFilter filter, String part) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java index 992f7418..1fb051f2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomLoadEvent.java @@ -26,11 +26,8 @@ public class RequestRoomLoadEvent extends MessageHandler { Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo()); - if (this.client.getHabbo().getRoomUnit() != null) - { - room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); - } - room.removeHabbo(this.client.getHabbo()); + room.removeHabbo(this.client.getHabbo(), true); + this.client.getHabbo().getHabboInfo().setCurrentRoom(null); } Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RoomSettingsSaveEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RoomSettingsSaveEvent.java index e80ce127..f85db766 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RoomSettingsSaveEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RoomSettingsSaveEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomCategory; import com.eu.habbo.habbohotel.rooms.RoomState; @@ -109,7 +110,7 @@ public class RoomSettingsSaveEvent extends MessageHandler message = Emulator.getTexts().getValue("scripter.warning.roomsettings.category.permission").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%category%", Emulator.getGameEnvironment().getRoomManager().getCategory(categoryId) + ""); } - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CloseDiceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CloseDiceEvent.java index 33e1ec1b..be480ddf 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CloseDiceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CloseDiceEvent.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionDice; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.users.HabboItem; @@ -38,7 +39,7 @@ public class CloseDiceEvent extends MessageHandler } else { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.packet.closedice").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%id%", item.getId() + "").replace("%itemname%", item.getBaseItem().getName())); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.packet.closedice").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%id%", item.getId() + "").replace("%itemname%", item.getBaseItem().getName())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItDeleteEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItDeleteEvent.java index e5b4663a..18f46d0f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItDeleteEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItDeleteEvent.java @@ -29,7 +29,7 @@ public class PostItDeleteEvent extends MessageHandler item.setRoomId(0); room.removeHabboItem(item); room.sendComposer(new RemoveWallItemComposer(item).compose()); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItPlaceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItPlaceEvent.java index c2417458..dfbbfd6f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItPlaceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItPlaceEvent.java @@ -36,7 +36,8 @@ public class PostItPlaceEvent extends MessageHandler item.needsUpdate(true); room.sendComposer(new AddWallItemComposer(item, this.client.getHabbo().getHabboInfo().getUsername()).compose()); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); + this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId())); + item.setFromGift(false); Emulator.getThreading().run(item); if (room.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItSaveDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItSaveDataEvent.java index df4b1803..fdc616b4 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItSaveDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PostItSaveDataEvent.java @@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.PostItColor; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; @@ -18,7 +19,7 @@ public class PostItSaveDataEvent extends MessageHandler if (text.length() > Emulator.getConfig().getInt("postit.charlimit")) { - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", Emulator.getTexts().getValue("scripter.warning.sticky.size").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%amount%", text.length() + "").replace("%limit%", "366")); + ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.sticky.size").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%amount%", text.length() + "").replace("%limit%", "366")); if (text.length() >= Emulator.getConfig().getInt("postit.charlimit") + 50) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemClothingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemClothingEvent.java index 179b4923..612360cf 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemClothingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemClothingEvent.java @@ -45,7 +45,7 @@ public class RedeemClothingEvent extends MessageHandler this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTile(tile); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(tile.x, tile.y, tile.relativeHeight()).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item, true).compose()); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_clothing (user_id, clothing_id) VALUES (?, ?)")) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java index 840d3b5a..106c2efb 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RedeemItemEvent.java @@ -12,6 +12,9 @@ import com.eu.habbo.messages.outgoing.users.UserCurrencyComposer; import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.furniture.FurnitureRedeemedEvent; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; +import gnu.trove.set.hash.THashSet; + +import java.util.ArrayList; public class RedeemItemEvent extends MessageHandler { @@ -29,6 +32,7 @@ public class RedeemItemEvent extends MessageHandler if(item != null && this.client.getHabbo().getHabboInfo().getId() == item.getUserId()) { boolean furnitureRedeemEventRegistered = Emulator.getPluginManager().isRegistered(FurnitureRedeemedEvent.class, true); + FurnitureRedeemedEvent furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), 0, FurnitureRedeemedEvent.CREDITS); if(item.getBaseItem().getName().startsWith("CF_") || item.getBaseItem().getName().startsWith("CFC_") || item.getBaseItem().getName().startsWith("DF_") || item.getBaseItem().getName().startsWith("PF_")) { @@ -45,19 +49,9 @@ public class RedeemItemEvent extends MessageHandler return; } - if(furnitureRedeemEventRegistered) - { - Event furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), credits, FurnitureRedeemedEvent.CREDITS); - Emulator.getPluginManager().fireEvent(furniRedeemEvent); - - if(furniRedeemEvent.isCancelled()) - return; - } - - this.client.getHabbo().getHabboInfo().addCredits(credits); - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); - - } else if (item.getBaseItem().getName().startsWith("PF_")) + furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), credits, FurnitureRedeemedEvent.CREDITS); + } + else if (item.getBaseItem().getName().startsWith("PF_")) { int pixels; @@ -71,17 +65,7 @@ public class RedeemItemEvent extends MessageHandler return; } - if(furnitureRedeemEventRegistered) - { - Event furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), pixels, FurnitureRedeemedEvent.PIXELS); - Emulator.getPluginManager().fireEvent(furniRedeemEvent); - - if(furniRedeemEvent.isCancelled()) - return; - } - - this.client.getHabbo().getHabboInfo().addPixels(pixels); - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); + furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), pixels, FurnitureRedeemedEvent.PIXELS); } else if (item.getBaseItem().getName().startsWith("DF_")) { @@ -108,39 +92,68 @@ public class RedeemItemEvent extends MessageHandler return; } - if(furnitureRedeemEventRegistered) - { - Event furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), points, FurnitureRedeemedEvent.DIAMONDS); - Emulator.getPluginManager().fireEvent(furniRedeemEvent); - - if(furniRedeemEvent.isCancelled()) - return; - } - - this.client.getHabbo().givePoints(pointsType, points); + furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), points, pointsType); } else if (item.getBaseItem().getName().startsWith("CF_diamond_")) { + int points; + try { - this.client.getHabbo().givePoints(Integer.valueOf(item.getBaseItem().getName().split("_")[2])); + points = Integer.valueOf(item.getBaseItem().getName().split("_")[2]); } catch (Exception e) { Emulator.getLogging().logErrorLine("Failed to parse redeemable diamonds furniture: " + item.getBaseItem().getName() + ". Must be in format of CF_diamond_"); return; } + + furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), points, FurnitureRedeemedEvent.DIAMONDS); } + if(furnitureRedeemEventRegistered) + { + Emulator.getPluginManager().fireEvent(furniRedeemEvent); + + if(furniRedeemEvent.isCancelled()) + return; + } + + if(furniRedeemEvent.amount < 1) + return; + + if(room.getHabboItem(item.getId()) == null) // plugins may cause a lag between which time the item can be removed from the room + return; + room.removeHabboItem(item); room.sendComposer(new RemoveFloorItemComposer(item).compose()); RoomTile t = room.getLayout().getTile(item.getX(), item.getY()); t.setStackHeight(room.getStackHeight(item.getX(), item.getY(), false)); room.updateTile(t); room.sendComposer(new UpdateStackHeightComposer(item.getX(), item.getY(), t.relativeHeight()).compose()); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); + + switch(furniRedeemEvent.currencyID) { + case FurnitureRedeemedEvent.CREDITS: + this.client.getHabbo().getHabboInfo().addCredits(furniRedeemEvent.amount); + this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); + break; + + case FurnitureRedeemedEvent.DIAMONDS: + this.client.getHabbo().givePoints(furniRedeemEvent.amount); + break; + + case FurnitureRedeemedEvent.PIXELS: + this.client.getHabbo().getHabboInfo().addPixels(furniRedeemEvent.amount); + this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); + break; + + default: + this.client.getHabbo().givePoints(furniRedeemEvent.currencyID, furniRedeemEvent.amount); + break; + } } } } } -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomPlaceItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomPlaceItemEvent.java index 2355b093..478a320f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomPlaceItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomPlaceItemEvent.java @@ -23,11 +23,6 @@ public class RoomPlaceItemEvent extends MessageHandler int itemId = -1; if (values.length != 0) itemId = Integer.valueOf(values[0]); - if(itemId < 0) - { - this.client.sendResponse(new BubbleAlertComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, FurnitureMovementError.INVALID_MOVE.errorCode)); - return; - } if(!this.client.getHabbo().getRoomUnit().isInRoom()) { @@ -122,7 +117,8 @@ public class RoomPlaceItemEvent extends MessageHandler } } - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); + this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId())); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item.getId()); + item.setFromGift(false); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java index e46ec8ae..e78db148 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ToggleFloorItemEvent.java @@ -97,7 +97,7 @@ public class ToggleFloorItemEvent extends MessageHandler //Do not move to onClick(). Wired could trigger it. if(item instanceof InteractionMonsterPlantSeed) { - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); int rarity = 0; if (item.getExtradata().isEmpty()) rarity = InteractionMonsterPlantSeed.randomRarityLevel(); else diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java index a93a4b1a..4b362122 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostMonsterplantEvent.java @@ -45,12 +45,7 @@ public class CompostMonsterplantEvent extends MessageHandler room.sendComposer(new AddFloorItemComposer(compost, this.client.getHabbo().getHabboInfo().getUsername()).compose()); } - pet.setRoom(null); - pet.setUserId(0); - room.removePet(petId); - room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); - pet.setRoomUnit(null); - + pet.removeFromRoom(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_pets WHERE id = ? LIMIT 1")) { statement.setInt(1, pet.getId()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideEvent.java deleted file mode 100644 index cd3562ec..00000000 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideEvent.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.eu.habbo.messages.incoming.rooms.pets; - -import com.eu.habbo.Emulator; -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.RoomTile; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; -import com.eu.habbo.threading.runnables.RoomUnitRideHorse; - -public class HorseRideEvent extends MessageHandler -{ - @Override - public void handle() throws Exception - { - int petId = this.packet.readInt(); - - if(this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) - return; - - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); - - if(!(pet instanceof HorsePet)) - return; - - if(this.client.getHabbo().getHabboInfo().getRiding() == null) - { - if (((HorsePet) pet).anyoneCanRide() || this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) - { - if (((HorsePet) pet).getRider() != null) - { - if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) - { - this.client.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(((HorsePet) pet).getRider(), 0, -1); - ((HorsePet) pet).getRider().getHabboInfo().setRiding(null); - ((HorsePet) pet).setRider(null); - pet.setTask(PetTasks.FREE); - } else - { - //TODO: Say somebody else is already riding. - return; - } - } - - RoomTile goalTile = this.client.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(this.client.getHabbo().getRoomUnit().getCurrentLocation(), this.client.getHabbo().getRoomUnit().getBodyRotation().getValue()); - - if (goalTile != null) - { - if (goalTile.equals(this.client.getHabbo().getRoomUnit().getCurrentLocation())) - { - this.client.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(this.client.getHabbo(), 77, -1); - this.client.getHabbo().getHabboInfo().setRiding((HorsePet) pet); - ((HorsePet) pet).setRider(this.client.getHabbo()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserEffectComposer(this.client.getHabbo().getRoomUnit()).compose()); - pet.setTask(PetTasks.RIDE); - } - else - { - pet.getRoomUnit().setGoalLocation(goalTile); - Emulator.getThreading().run(new RoomUnitRideHorse((HorsePet) pet, this.client.getHabbo(), goalTile)); - } - } - } - } - else - { - // TODO : THIS IS NOT THE CORRECT WAY OF HANDLING MOUNTING. CHECK HABBO.COM. THE HORSE SHOULD NOT COME TO YOU. YOU SHOULD GO TO THE HORSE. - this.client.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(this.client.getHabbo(), 0, -1); - ((HorsePet) pet).setRider(null); - pet.setTask(PetTasks.FREE); - this.client.getHabbo().getHabboInfo().setRiding(null); - this.client.getHabbo().getRoomUnit().setGoalLocation(this.client.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(this.client.getHabbo().getRoomUnit().getCurrentLocation(), this.client.getHabbo().getRoomUnit().getBodyRotation().getValue())); - } - } -} diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideSettingsEvent.java deleted file mode 100644 index e2b3e62f..00000000 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideSettingsEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.eu.habbo.messages.incoming.rooms.pets; - -import com.eu.habbo.habbohotel.pets.HorsePet; -import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetHorseFigureComposer; - -public class HorseRideSettingsEvent extends MessageHandler -{ - @Override - public void handle() throws Exception - { - int petId = this.packet.readInt(); - - if(this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) - return; - - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); - - if(pet == null || pet.getUserId() != this.client.getHabbo().getHabboInfo().getId() || !(pet instanceof HorsePet)) - return; - - ((HorsePet) pet).setAnyoneCanRide(!((HorsePet) pet).anyoneCanRide()); - ((HorsePet) pet).needsUpdate = true; - - this.client.sendResponse(new RoomPetHorseFigureComposer((HorsePet) pet)); - } -} diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPackageNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPackageNameEvent.java index 8c26286e..36893168 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPackageNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPackageNameEvent.java @@ -70,7 +70,7 @@ public class PetPackageNameEvent extends MessageHandler pet.needsUpdate = true; pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getX(), item.getY())); pet.getRoomUnit().setZ(item.getZ()); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); room.removeHabboItem(item); room.sendComposer(new RemoveFloorItemComposer(item).compose()); RoomTile tile = room.getLayout().getTile(item.getX(), item.getY()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java index 8cac95c8..12c7e41c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java @@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; @@ -35,12 +36,15 @@ public class PetPickupEvent extends MessageHandler this.client.sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(Emulator.getTexts().getValue("error.pets.max.inventory"), this.client.getHabbo(), this.client.getHabbo(), RoomChatMessageBubbles.ALERT))); return; } - room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); - room.removePet(petId); - pet.setRoomUnit(null); - pet.setRoom(null); - pet.needsUpdate = true; + if(pet instanceof RideablePet) { + RideablePet rideablePet = (RideablePet)pet; + if(rideablePet.getRider() != null) { + rideablePet.getRider().getHabboInfo().dismountPet(true); + } + } + + pet.removeFromRoom(); Emulator.getThreading().run(pet); if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideEvent.java new file mode 100644 index 00000000..6b84a1c4 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideEvent.java @@ -0,0 +1,60 @@ +package com.eu.habbo.messages.incoming.rooms.pets; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.RideablePet; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.threading.runnables.RoomUnitRidePet; +import java.util.List; + +public class PetRideEvent extends MessageHandler +{ + @Override + public void handle() throws Exception + { + int petId = this.packet.readInt(); + Habbo habbo = this.client.getHabbo(); + Room room = habbo.getHabboInfo().getCurrentRoom(); + + if(room == null) + return; + + Pet pet = room.getPet(petId); + + if(!(pet instanceof RideablePet)) + return; + + RideablePet rideablePet = (RideablePet)pet; + + //dismount + if(habbo.getHabboInfo().getRiding() != null) + { + habbo.getHabboInfo().dismountPet(); + return; + } + + // someone is already on it + if(rideablePet.getRider() != null) + return; + + // check if able to ride + if(!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) + return; + + List availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentLocation()); + + // if cant reach it then cancel + if(availableTiles.isEmpty()) + return; + + RoomTile goalTile = availableTiles.get(0); + habbo.getRoomUnit().setGoalLocation(goalTile); + Emulator.getThreading().run(new RoomUnitRidePet(rideablePet, habbo, goalTile)); + rideablePet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp()); + rideablePet.getRoomUnit().stopWalking(); + } +} diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideSettingsEvent.java new file mode 100644 index 00000000..bc452af6 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideSettingsEvent.java @@ -0,0 +1,37 @@ +package com.eu.habbo.messages.incoming.rooms.pets; + +import com.eu.habbo.habbohotel.pets.HorsePet; +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetHorseFigureComposer; + +public class PetRideSettingsEvent extends MessageHandler +{ + @Override + public void handle() throws Exception + { + int petId = this.packet.readInt(); + + if(this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + return; + + Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + + if(pet == null || pet.getUserId() != this.client.getHabbo().getHabboInfo().getId() || !(pet instanceof RideablePet)) + return; + + RideablePet rideablePet = ((RideablePet) pet); + + rideablePet.setAnyoneCanRide(!rideablePet.anyoneCanRide()); + rideablePet.needsUpdate = true; + + if(!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { + rideablePet.getRider().getHabboInfo().dismountPet(); + } + + if(pet instanceof HorsePet) { + this.client.sendResponse(new RoomPetHorseFigureComposer((HorsePet) pet)); + } + } +} diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseUseItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java similarity index 98% rename from src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseUseItemEvent.java rename to src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java index c8f6bf6a..6fd22971 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseUseItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java @@ -15,7 +15,7 @@ import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetHorseFigureComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; -public class HorseUseItemEvent extends MessageHandler +public class PetUseItemEvent extends MessageHandler { @Override public void handle() throws Exception @@ -103,7 +103,7 @@ public class HorseUseItemEvent extends MessageHandler Emulator.getThreading().run(pet); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomPetHorseFigureComposer((HorsePet) pet).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } else if (pet instanceof MonsterplantPet) @@ -124,7 +124,7 @@ public class HorseUseItemEvent extends MessageHandler this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantHealer")); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } else if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_fert")) @@ -143,7 +143,7 @@ public class HorseUseItemEvent extends MessageHandler this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); pet.cycle(); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } else if (item.getBaseItem().getName().startsWith("mnstr_rebreed")) @@ -167,7 +167,7 @@ public class HorseUseItemEvent extends MessageHandler this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RequestPetInformationEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RequestPetInformationEvent.java index 74648373..11c71438 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RequestPetInformationEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RequestPetInformationEvent.java @@ -21,7 +21,7 @@ public class RequestPetInformationEvent extends MessageHandler if(pet != null) { - this.client.sendResponse(new PetInformationComposer(pet, room)); + this.client.sendResponse(new PetInformationComposer(pet, room, this.client.getHabbo())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserGiveRespectEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserGiveRespectEvent.java index cea256a4..4ec51ba3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserGiveRespectEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserGiveRespectEvent.java @@ -1,7 +1,9 @@ package com.eu.habbo.messages.incoming.rooms.users; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.plugin.events.users.UserRespectedEvent; public class RoomUserGiveRespectEvent extends MessageHandler { @@ -14,6 +16,11 @@ public class RoomUserGiveRespectEvent extends MessageHandler { Habbo target = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(userId); + if(Emulator.getPluginManager().isRegistered(UserRespectedEvent.class, false)) { + if(Emulator.getPluginManager().fireEvent(new UserRespectedEvent(target, this.client.getHabbo())).isCancelled()) + return; + } + this.client.getHabbo().respect(target); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserShoutEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserShoutEvent.java index 402c56ad..2bcc3528 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserShoutEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserShoutEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.users; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatType; import com.eu.habbo.messages.incoming.MessageHandler; @@ -40,7 +41,7 @@ public class RoomUserShoutEvent extends MessageHandler else { String reportMessage = Emulator.getTexts().getValue("scripter.warning.chat.length").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%length%", message.getMessage().length() + ""); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", reportMessage); + ScripterManager.scripterDetected(this.client, reportMessage); Emulator.getLogging().logUserLine(reportMessage); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserTalkEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserTalkEvent.java index c1590b04..f5aa92d4 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserTalkEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserTalkEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.users; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatType; @@ -41,7 +42,7 @@ public class RoomUserTalkEvent extends MessageHandler { else { String reportMessage = Emulator.getTexts().getValue("scripter.warning.chat.length").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%length%", message.getMessage().length() + ""); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", reportMessage); + ScripterManager.scripterDetected(this.client, reportMessage); Emulator.getLogging().logUserLine(reportMessage); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWhisperEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWhisperEvent.java index 5a70a64f..9455dcac 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWhisperEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserWhisperEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.users; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatType; import com.eu.habbo.messages.incoming.MessageHandler; @@ -36,7 +37,7 @@ public class RoomUserWhisperEvent extends MessageHandler else { String reportMessage = Emulator.getTexts().getValue("scripter.warning.chat.length").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%length%", chatMessage.getMessage().length() + ""); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", reportMessage); + ScripterManager.scripterDetected(this.client, reportMessage); Emulator.getLogging().logUserLine(reportMessage); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/TradeAcceptEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/TradeAcceptEvent.java index 88c30feb..8a747f0a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/TradeAcceptEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/TradeAcceptEvent.java @@ -10,6 +10,10 @@ public class TradeAcceptEvent extends MessageHandler public void handle() throws Exception { Habbo habbo = this.client.getHabbo(); + + if(habbo == null || habbo.getHabboInfo() == null || habbo.getHabboInfo().getCurrentRoom() == null) + return; + RoomTrade trade = habbo.getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(habbo); if(trade == null) diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/UserSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/UserSaveLookEvent.java index 8197ed57..503a666d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/UserSaveLookEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/UserSaveLookEvent.java @@ -2,11 +2,13 @@ package com.eu.habbo.messages.incoming.users; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; +import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.users.HabboGender; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer; import com.eu.habbo.messages.outgoing.users.UpdateUserLookComposer; import com.eu.habbo.plugin.events.users.UserSavedLookEvent; +import com.eu.habbo.util.figure.FigureUtil; public class UserSaveLookEvent extends MessageHandler { @@ -23,12 +25,13 @@ public class UserSaveLookEvent extends MessageHandler catch (IllegalArgumentException e) { String message = Emulator.getTexts().getValue("scripter.warning.look.gender").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%gender%", genderCode); - Emulator.getGameEnvironment().getModToolManager().quickTicket(this.client.getHabbo(), "Scripter", message); + ScripterManager.scripterDetected(this.client, message); Emulator.getLogging().logUserLine(message); return; } String look = this.packet.readString(); + UserSavedLookEvent lookEvent = new UserSavedLookEvent(this.client.getHabbo(), gender, look); Emulator.getPluginManager().fireEvent(lookEvent); if(lookEvent.isCancelled()) diff --git a/src/main/java/com/eu/habbo/messages/outgoing/catalog/DiscountComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/catalog/DiscountComposer.java index 1a44a341..3a900fc1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/catalog/DiscountComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/catalog/DiscountComposer.java @@ -6,17 +6,27 @@ import com.eu.habbo.messages.outgoing.Outgoing; public class DiscountComposer extends MessageComposer { + public static int MAXIMUM_ALLOWED_ITEMS = 100; + public static int DISCOUNT_BATCH_SIZE = 6; + public static int DISCOUNT_AMOUNT_PER_BATCH = 1; + public static int MINIMUM_DISCOUNTS_FOR_BONUS = 1; + public static int[] ADDITIONAL_DISCOUNT_THRESHOLDS = new int[]{40, 99}; + @Override public ServerMessage compose() { this.response.init(Outgoing.DiscountComposer); - this.response.appendInt(100); - this.response.appendInt(6); - this.response.appendInt(1); - this.response.appendInt(1); - this.response.appendInt(2); - this.response.appendInt(40); - this.response.appendInt(99); + + this.response.appendInt(MAXIMUM_ALLOWED_ITEMS); + this.response.appendInt(DISCOUNT_BATCH_SIZE); + this.response.appendInt(DISCOUNT_AMOUNT_PER_BATCH); + this.response.appendInt(MINIMUM_DISCOUNTS_FOR_BONUS); + + this.response.appendInt(ADDITIONAL_DISCOUNT_THRESHOLDS.length); + for (int threshold : ADDITIONAL_DISCOUNT_THRESHOLDS) { + this.response.appendInt(threshold); + } + return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/catalog/RedeemVoucherErrorComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/catalog/RedeemVoucherErrorComposer.java index 63152f22..ab2972b0 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/catalog/RedeemVoucherErrorComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/catalog/RedeemVoucherErrorComposer.java @@ -20,7 +20,7 @@ public class RedeemVoucherErrorComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.RedeemVoucherErrorComposer); - this.response.appendInt(this.code); + this.response.appendString(this.code + ""); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendChatMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendChatMessageComposer.java index 41bc517e..aad0cb77 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendChatMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendChatMessageComposer.java @@ -10,35 +10,37 @@ import com.eu.habbo.messages.outgoing.Outgoing; public class FriendChatMessageComposer extends MessageComposer { private final Message message; + private final int toId; + private final int fromId; public FriendChatMessageComposer(Message message) { this.message = message; + this.toId = message.getFromId(); + this.fromId = message.getFromId(); + } + + public FriendChatMessageComposer(Message message, int toId, int fromId) { + this.message = message; + this.toId = toId; + this.fromId = fromId; } @Override public ServerMessage compose() { this.response.init(Outgoing.FriendChatMessageComposer); - - if (this.message.getToId() == -1) - { - this.response.appendInt(-1); - } - else - { - this.response.appendInt(this.message.getFromId()); - } + this.response.appendInt(this.toId); this.response.appendString(this.message.getMessage()); this.response.appendInt(Emulator.getIntUnixTimestamp() - this.message.getTimestamp()); - if (this.message.getToId() == -1) //TO Staff Chat + if(this.toId < 0) // group chat { String name = "AUTO_MODERATOR"; String look = "lg-5635282-1193.hd-3091-1.sh-3089-73.cc-156282-64.hr-831-34.ha-1012-1186.ch-3050-62-62"; - if (this.message.getFromId() != -1) + if (this.fromId > 0) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.message.getFromId()); + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.fromId); if (habbo != null) { @@ -50,7 +52,7 @@ public class FriendChatMessageComposer extends MessageComposer name = "UNKNOWN"; } } - this.response.appendString(name + "/" + look + "/" + this.message.getFromId()); + this.response.appendString(name + "/" + look + "/" + this.fromId); } return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendsComposer.java index 4c698ba0..10ac11cb 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/friends/FriendsComposer.java @@ -32,7 +32,7 @@ public class FriendsComposer extends MessageComposer //this.response.appendInt(3); //Club level this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS); this.response.appendInt(this.habbo.hasPermission("acc_infinite_friends") ? Integer.MAX_VALUE : Messenger.MAXIMUM_FRIENDS); - this.response.appendInt(this.habbo.getMessenger().getFriends().size() + (this.habbo.hasPermission("acc_staff_chat") ? 1 : 0)); + this.response.appendInt(this.habbo.getMessenger().getFriends().size()/* + (this.habbo.hasPermission("acc_staff_chat") ? 1 : 0)*/); for (Map.Entry row : this.habbo.getMessenger().getFriends().entrySet()) { this.response.appendInt(row.getKey()); @@ -51,7 +51,7 @@ public class FriendsComposer extends MessageComposer this.response.appendShort(row.getValue().getRelation()); } - if(this.habbo.hasPermission("acc_staff_chat")) + /*if(this.habbo.hasPermission("acc_staff_chat")) { this.response.appendInt(-1); this.response.appendString("Staff Chat"); @@ -67,7 +67,8 @@ public class FriendsComposer extends MessageComposer this.response.appendBoolean(false); this.response.appendBoolean(false); this.response.appendShort(0); - } + }*/ + return this.response; } catch(Exception e) diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java index 869eaf67..acb91038 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildInfoComposer.java @@ -50,7 +50,7 @@ public class GuildInfoComposer extends MessageComposer this.response.appendString(this.guild.getOwnerName()); this.response.appendBoolean(this.newWindow); - this.response.appendBoolean(this.guild.getRights() == 0); //User can place furni. + this.response.appendBoolean(this.guild.getRights()); //User can place furni. this.response.appendInt((adminPermissions || this.guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) ? this.guild.getRequestCount() : 0); //Guild invites count. this.response.appendBoolean(this.guild.hasForum()); //Unknown return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildManageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildManageComposer.java index af0f5c20..8dd1bf77 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildManageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildManageComposer.java @@ -19,8 +19,8 @@ public class GuildManageComposer extends MessageComposer { this.response.init(Outgoing.GuildManageComposer); this.response.appendInt(1); - this.response.appendInt(1); - this.response.appendString("Room Name"); + this.response.appendInt(guild.getRoomId()); + this.response.appendString(guild.getRoomName()); this.response.appendBoolean(false); this.response.appendBoolean(true); this.response.appendInt(this.guild.getId()); @@ -30,7 +30,7 @@ public class GuildManageComposer extends MessageComposer this.response.appendInt(this.guild.getColorOne()); this.response.appendInt(this.guild.getColorTwo()); this.response.appendInt(this.guild.getState().state); - this.response.appendInt(this.guild.getRights()); + this.response.appendInt(this.guild.getRights() ? 0 : 1); this.response.appendBoolean(false); this.response.appendString(""); this.response.appendInt(5); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumAddCommentComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumAddCommentComposer.java index 936c2d76..c953e40b 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumAddCommentComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumAddCommentComposer.java @@ -1,16 +1,15 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; public class GuildForumAddCommentComposer extends MessageComposer { - private final GuildForumComment comment; + private final ForumThreadComment comment; - public GuildForumAddCommentComposer(GuildForumComment comment) - { + public GuildForumAddCommentComposer(ForumThreadComment comment) { this.comment = comment; } @@ -18,7 +17,7 @@ public class GuildForumAddCommentComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.GuildForumAddCommentComposer); - this.response.appendInt(this.comment.getGuildId()); //guild_id + this.response.appendInt(this.comment.getThread().getGuildId()); //guild_id this.response.appendInt(this.comment.getThreadId()); //thread_id this.comment.serialize(this.response); //Comment return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumCommentsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumCommentsComposer.java index 500c1284..43252148 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumCommentsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumCommentsComposer.java @@ -1,20 +1,19 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; - -import java.util.List; +import java.util.Collection; public class GuildForumCommentsComposer extends MessageComposer { private final int guildId; private final int threadId; private final int index; - private final List guildForumCommentList; + private final Collection guildForumCommentList; - public GuildForumCommentsComposer(int guildId, int threadId, int index, List guildForumCommentList) + public GuildForumCommentsComposer(int guildId, int threadId, int index, Collection guildForumCommentList) { this.guildId = guildId; this.threadId = threadId; @@ -32,7 +31,7 @@ public class GuildForumCommentsComposer extends MessageComposer this.response.appendInt(this.index); //start_index this.response.appendInt(this.guildForumCommentList.size()); - for (final GuildForumComment comment : this.guildForumCommentList) + for (ForumThreadComment comment : this.guildForumCommentList) { comment.serialize(this.response); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumDataComposer.java index 206df7e3..7fb4d878 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumDataComposer.java @@ -4,30 +4,39 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildMember; import com.eu.habbo.habbohotel.guilds.GuildRank; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; +import gnu.trove.set.hash.THashSet; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + public class GuildForumDataComposer extends MessageComposer { - public final GuildForum forum; + public final Guild guild; public Habbo habbo; - public GuildForumDataComposer(GuildForum forum, Habbo habbo) { - this.forum = forum; + public GuildForumDataComposer(Guild guild, Habbo habbo) { + this.guild = guild; this.habbo = habbo; } @Override public ServerMessage compose() { - this.response.init(Outgoing.GuildForumDataComposer); - { - this.forum.serializeUserForum(this.response, this.habbo); - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.forum.getGuild()); + try { + this.response.init(Outgoing.GuildForumDataComposer); + serializeForumData(this.response, guild, habbo); + GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo); - boolean isAdmin = member != null && (member.getRank() == GuildRank.MOD || member.getRank() == GuildRank.ADMIN || guild.getOwnerId() == this.habbo.getHabboInfo().getId()); + boolean isAdmin = member != null && (member.getRank().type < GuildRank.MEMBER.type || guild.getOwnerId() == this.habbo.getHabboInfo().getId()); boolean isStaff = this.habbo.hasPermission("acc_modtool_ticket_q"); String errorRead = ""; @@ -46,7 +55,7 @@ public class GuildForumDataComposer extends MessageComposer { } else if (guild.canPostMessages().state == 2 && !isAdmin && !isStaff) { errorPost = "not_admin"; } else if (guild.canPostMessages().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) { - errorPost = "now_owner"; + errorPost = "not_owner"; } if (guild.canPostThreads().state == 1 && member == null && !isStaff) { @@ -54,13 +63,14 @@ public class GuildForumDataComposer extends MessageComposer { } else if (guild.canPostThreads().state == 2 && !isAdmin && !isStaff) { errorStartThread = "not_admin"; } else if (guild.canPostThreads().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) { - errorStartThread = "now_owner"; + errorStartThread = "not_owner"; } - if (guild.canModForum().state == 2 && !isAdmin && !isStaff) { + if (guild.canModForum().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) { + errorModerate = "not_owner"; + } + else if (!isAdmin && !isStaff) { errorModerate = "not_admin"; - } else if (guild.canModForum().state == 3 && guild.getOwnerId() != this.habbo.getHabboInfo().getId() && !isStaff) { - errorModerate = "now_owner"; } this.response.appendInt(guild.canReadForum().state); @@ -75,6 +85,80 @@ public class GuildForumDataComposer extends MessageComposer { this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId()); //Forum Settings this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId() || isStaff); //Can Mod (staff) } + catch (Exception e) { + e.printStackTrace(); + return new ConnectionErrorComposer(500).compose(); + } + return this.response; } + + public static void serializeForumData(ServerMessage response, Guild guild, Habbo habbo) throws SQLException { + + final THashSet forumThreads = ForumThread.getByGuildId(guild.getId()); + int lastSeenAt = 0; + + int totalComments = 0; + int newComments = 0; + int totalThreads = 0; + ForumThreadComment lastComment = null; + + synchronized (forumThreads) { + for (ForumThread thread : forumThreads) { + totalThreads++; + totalComments += thread.getPostsCount(); + + ForumThreadComment comment = thread.getLastComment(); + if (comment != null && (lastComment == null || lastComment.getCreatedAt() < comment.getCreatedAt())) { + lastComment = comment; + } + } + } + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement( + "SELECT COUNT(*) " + + "FROM guilds_forums_threads A " + + "JOIN ( " + + "SELECT * " + + "FROM `guilds_forums_comments` " + + "WHERE `id` IN ( " + + "SELECT id " + + "FROM `guilds_forums_comments` B " + + "ORDER BY B.`id` ASC " + + ") " + + "ORDER BY `id` DESC " + + ") B ON A.`id` = B.`thread_id` " + + "WHERE A.`guild_id` = ? AND B.`created_at` > ?" + )) + { + statement.setInt(1, guild.getId()); + statement.setInt(2, lastSeenAt); + + ResultSet set = statement.executeQuery(); + while(set.next()) { + newComments = set.getInt(1); + } + } + catch (SQLException e) + { + Emulator.getLogging().logSQLException(e); + } + + response.appendInt(guild.getId()); + + response.appendString(guild.getName()); + response.appendString(guild.getDescription()); + response.appendString(guild.getBadge()); + + response.appendInt(totalThreads); + response.appendInt(0); //Rating + + response.appendInt(totalComments); //Total comments + response.appendInt(newComments); //Unread comments + + response.appendInt(lastComment != null ? lastComment.getThreadId() : -1); + response.appendInt(lastComment != null ? lastComment.getUserId() : -1); + response.appendString(lastComment != null && lastComment.getHabbo() != null ? lastComment.getHabbo().getHabboInfo().getUsername() : ""); + response.appendInt(lastComment != null ? Emulator.getIntUnixTimestamp() - lastComment.getCreatedAt() : 0); + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumListComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumListComposer.java index e659fe7c..c885547d 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumListComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumListComposer.java @@ -1,41 +1,57 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; - -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; +import gnu.trove.set.hash.THashSet; +import java.sql.SQLException; +import java.util.Iterator; public class GuildForumListComposer extends MessageComposer { - private final List forums; + private final THashSet guilds; private final Habbo habbo; - private final int viewMode; - private final int startIndex; + private final int mode; + private final int index; - public GuildForumListComposer(List forums, Habbo habbo, int viewMode, int page) { - this.forums = forums; + public GuildForumListComposer(THashSet guilds, Habbo habbo, int mode, int index) { + this.guilds = guilds; this.habbo = habbo; - this.viewMode = viewMode; - this.startIndex = page; + this.mode = mode; + this.index = index; } @Override public ServerMessage compose() { - forums.removeIf(Objects::isNull); - - List guilds = forums.stream().skip(this.startIndex).limit(20).map(GuildForum::getGuild).collect(Collectors.toList()); - this.response.init(Outgoing.GuildForumListComposer); - this.response.appendInt(this.viewMode); - this.response.appendInt(guilds.size()); - this.response.appendInt(0); - this.response.appendInt(this.forums.size()); - for (final GuildForum forum : this.forums) { - forum.serializeUserForum(this.response, this.habbo); + this.response.appendInt(this.mode); + this.response.appendInt(this.guilds.size()); + + this.response.appendInt(this.index); + + Iterator it = guilds.iterator(); + int count = guilds.size() > 20 ? 20 : guilds.size(); + + this.response.appendInt(count); + + for(int i = 0; i < index; i++) { + if(!it.hasNext()) + break; + + it.next(); + } + + for(int i = 0; i < count; i++) { + if(!it.hasNext()) + break; + + try { + GuildForumDataComposer.serializeForumData(this.response, it.next(), habbo); + } catch (SQLException e) { + return new ConnectionErrorComposer(500).compose(); + } } return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadMessagesComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadMessagesComposer.java index 92af62de..04c37175 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadMessagesComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadMessagesComposer.java @@ -1,15 +1,15 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; public class GuildForumThreadMessagesComposer extends MessageComposer { - public final GuildForumThread thread; + public final ForumThread thread; - public GuildForumThreadMessagesComposer(GuildForumThread thread) + public GuildForumThreadMessagesComposer(ForumThread thread) { this.thread = thread; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadsComposer.java index 112395be..2c0493a8 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/GuildForumThreadsComposer.java @@ -1,28 +1,61 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; +import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import com.eu.habbo.messages.outgoing.handshake.ConnectionErrorComposer; + +import java.util.*; public class GuildForumThreadsComposer extends MessageComposer { - public final GuildForum forum; + public final Guild guild; public final int index; - public GuildForumThreadsComposer(GuildForum forum, int index) + public GuildForumThreadsComposer(Guild guild, int index) { - this.forum = forum; + this.guild = guild; this.index = index; } @Override public ServerMessage compose() { + ArrayList threads; + + try { + threads = new ArrayList<>(ForumThread.getByGuildId(guild.getId())); + } catch (Exception e) { + return new ConnectionErrorComposer(500).compose(); + } + + threads.sort(Comparator.comparingInt(o -> o.isPinned() ? Integer.MAX_VALUE : o.getUpdatedAt())); + Collections.reverse(threads); + + Iterator it = threads.iterator(); + int count = threads.size() > 20 ? 20 : threads.size(); + this.response.init(Outgoing.GuildForumThreadsComposer); - this.response.appendInt(this.forum.getGuild()); + this.response.appendInt(this.guild.getId()); this.response.appendInt(this.index); - this.forum.serializeThreads(this.response); + this.response.appendInt(count); + + for(int i = 0; i < index; i++) { + if(!it.hasNext()) + break; + + it.next(); + } + + for(int i = 0; i < count; i++) { + if(!it.hasNext()) + break; + + it.next().serialize(this.response); + } + return this.response; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/PostUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/PostUpdateMessageComposer.java index 23356707..ac632494 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/PostUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/PostUpdateMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.guilds.forums; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumComment; +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -9,9 +9,9 @@ public class PostUpdateMessageComposer extends MessageComposer { public final int guildId; public final int threadId; - public final GuildForumComment comment; + public final ForumThreadComment comment; - public PostUpdateMessageComposer(int guildId, int threadId, GuildForumComment comment) + public PostUpdateMessageComposer(int guildId, int threadId, ForumThreadComment comment) { this.guildId = guildId; this.threadId = threadId; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ThreadUpdatedMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ThreadUpdatedMessageComposer.java index 5f7eb9b9..4a12236b 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ThreadUpdatedMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ThreadUpdatedMessageComposer.java @@ -3,8 +3,7 @@ package com.eu.habbo.messages.outgoing.guilds.forums; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.guilds.GuildRank; -import com.eu.habbo.habbohotel.guilds.forums.GuildForum; -import com.eu.habbo.habbohotel.guilds.forums.GuildForumThread; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -13,9 +12,10 @@ import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; public class ThreadUpdatedMessageComposer extends MessageComposer { - public final GuildForumThread thread; - public final GuildForum forum; + public final Guild guild; + + public final ForumThread thread; private final Habbo habbo; @@ -23,21 +23,16 @@ public class ThreadUpdatedMessageComposer extends MessageComposer { private final boolean isLocked; - public ThreadUpdatedMessageComposer(GuildForum forum, Integer thread, Habbo habbo, boolean isPinned, boolean isLocked) { - this.forum = forum; + public ThreadUpdatedMessageComposer(Guild guild, ForumThread thread, Habbo habbo, boolean isPinned, boolean isLocked) { + this.guild = guild; this.habbo = habbo; - this.thread = forum.getThread(thread); + this.thread = thread; this.isPinned = isPinned; this.isLocked = isLocked; } @Override public ServerMessage compose() { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(forum.getGuild()); - - if (this.thread == null) - return null; - if (isPinned != thread.isPinned()) { this.habbo.getClient().sendResponse(new BubbleAlertComposer(isPinned ? BubbleAlertKeys.FORUMS_THREAD_PINNED.key : BubbleAlertKeys.FORUMS_THREAD_UNPINNED.key).compose()); } @@ -53,17 +48,11 @@ public class ThreadUpdatedMessageComposer extends MessageComposer { this.thread.setPinned(isPinned); this.thread.setLocked(isLocked); - this.response.init(Outgoing.ThreadUpdateMessageComposer); - - this.response.appendInt(this.thread.getGuildId()); - - this.thread.serialize(this.response); - - guild.needsUpdate = true; - Emulator.getThreading().run(this.thread); - Emulator.getThreading().run(guild); + this.response.init(Outgoing.ThreadUpdateMessageComposer); + this.response.appendInt(this.thread.getGuildId()); + this.thread.serialize(this.response); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/handshake/ConnectionErrorComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/handshake/ConnectionErrorComposer.java new file mode 100644 index 00000000..53d24db6 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/outgoing/handshake/ConnectionErrorComposer.java @@ -0,0 +1,35 @@ +package com.eu.habbo.messages.outgoing.handshake; + +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.MessageComposer; +import com.eu.habbo.messages.outgoing.Outgoing; + +public class ConnectionErrorComposer extends MessageComposer +{ + private final int messageId; + private final int errorCode; + private final String timestamp; + + public ConnectionErrorComposer(int errorCode) { + this.messageId = 0; + this.errorCode = errorCode; + this.timestamp = ""; + } + + public ConnectionErrorComposer(int messageId, int errorCode, String timestamp) { + this.messageId = messageId; + this.errorCode = errorCode; + this.timestamp = timestamp; + } + + @Override + public ServerMessage compose() + { + this.response.init(Outgoing.ConnectionErrorComposer); + this.response.appendInt(this.messageId); + this.response.appendInt(this.errorCode); + this.response.appendString(this.timestamp); + + return this.response; + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/AddHabboItemComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/AddHabboItemComposer.java index 2af53017..a470601c 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/AddHabboItemComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/AddHabboItemComposer.java @@ -6,19 +6,57 @@ import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; import gnu.trove.set.hash.THashSet; +import java.util.List; +import java.util.Map; + public class AddHabboItemComposer extends MessageComposer { + public enum AddHabboItemCategory { + OWNED_FURNI(1), + RENTED_FURNI(2), + PET(3), + BADGE(4), + BOT(5), + GAME(6); + + public final int number; + + AddHabboItemCategory(int number) + { + this.number = number; + } + } + private THashSet itemsList; private HabboItem item; - public AddHabboItemComposer(THashSet itemsList) - { + private int[] ids; + private AddHabboItemCategory category; + + private Map> entries; + + public AddHabboItemComposer(THashSet itemsList) { this.itemsList = itemsList; + this.category = AddHabboItemCategory.OWNED_FURNI; } - public AddHabboItemComposer(HabboItem item) - { + public AddHabboItemComposer(HabboItem item) { this.item = item; + this.category = AddHabboItemCategory.OWNED_FURNI; + } + + public AddHabboItemComposer(int[] ids, AddHabboItemCategory category) { + this.ids = ids; + this.category = category; + } + + public AddHabboItemComposer(int id, AddHabboItemCategory category) { + this.ids = new int[]{id}; + this.category = category; + } + + public AddHabboItemComposer(Map> entries) { + this.entries = entries; } @Override @@ -26,22 +64,39 @@ public class AddHabboItemComposer extends MessageComposer { this.response.init(Outgoing.AddHabboItemComposer); - if(this.item == null) - { + if (this.ids != null) { + this.response.appendInt(1); + + this.response.appendInt(this.category.number); + this.response.appendInt(this.ids.length); + for (int id : this.ids) { + this.response.appendInt(id); + } + } else if (this.entries != null) { + this.response.appendInt(this.entries.size()); + + for (Map.Entry> item : this.entries.entrySet()) { + this.response.appendInt(item.getKey().number); + + this.response.appendInt(item.getValue().size()); + for (int id : item.getValue()) { + this.response.appendInt(id); + } + } + } else if (this.item == null) { this.response.appendInt(1); this.response.appendInt(1); this.response.appendInt(this.itemsList.size()); for (HabboItem habboItem : this.itemsList) { this.response.appendInt(habboItem.getId()); } - } - else - { + } else { this.response.appendInt(1); this.response.appendInt(1); this.response.appendInt(1); this.response.appendInt(this.item.getId()); } + return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java index 981ae02b..6073a2f3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryItemsComposer.java @@ -47,7 +47,7 @@ public class InventoryItemsComposer extends MessageComposer implements TIntObjec @Override public boolean execute(int a, HabboItem habboItem) { - this.response.appendInt(habboItem.getId()); + this.response.appendInt(habboItem.getGiftAdjustedId()); this.response.appendString(habboItem.getBaseItem().getType().code); this.response.appendInt(habboItem.getId()); this.response.appendInt(habboItem.getBaseItem().getSpriteId()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryUpdateItemComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryUpdateItemComposer.java index 7ec74e1e..82567fb2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryUpdateItemComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/InventoryUpdateItemComposer.java @@ -19,8 +19,7 @@ public class InventoryUpdateItemComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.InventoryItemUpdateComposer); - this.response.appendInt(2); - this.response.appendInt(this.habboItem.getId()); + this.response.appendInt(this.habboItem.getGiftAdjustedId()); this.response.appendString(this.habboItem.getBaseItem().getType().code); this.response.appendInt(this.habboItem.getId()); this.response.appendInt(this.habboItem.getBaseItem().getSpriteId()); @@ -55,7 +54,7 @@ public class InventoryUpdateItemComposer extends MessageComposer this.response.appendBoolean(false); this.response.appendInt(-1); - if (this.habboItem.getBaseItem().getType() != FurnitureType.WALL) { + if (this.habboItem.getBaseItem().getType() == FurnitureType.FLOOR) { this.response.appendString(""); //slotId this.response.appendInt(0); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolComposer.java index cce3043f..6c654c28 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolComposer.java @@ -3,11 +3,16 @@ package com.eu.habbo.messages.outgoing.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolCategory; import com.eu.habbo.habbohotel.modtool.ModToolIssue; +import com.eu.habbo.habbohotel.modtool.ModToolTicketState; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import gnu.trove.map.hash.THashMap; import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.set.hash.THashSet; + +import java.util.Iterator; public class ModToolComposer extends MessageComposer implements TObjectProcedure { @@ -25,11 +30,28 @@ public class ModToolComposer extends MessageComposer implements TObjectProcedure if(this.habbo.hasPermission("acc_modtool_ticket_q")) { - this.response.appendInt(Emulator.getGameEnvironment().getModToolManager().getTickets().size()); //tickets + THashSet openTickets = new THashSet<>(); - for (ModToolIssue issue : Emulator.getGameEnvironment().getModToolManager().getTickets().values()) + THashMap tickets = Emulator.getGameEnvironment().getModToolManager().getTickets(); + + for(ModToolIssue t : tickets.values()) { + if(t.state != ModToolTicketState.CLOSED) + openTickets.add(t); + } + + int ticketsCount = openTickets.size(); + + if(ticketsCount > 100) { + ticketsCount = 100; + } + + this.response.appendInt(ticketsCount); //tickets + + Iterator it = openTickets.iterator(); + + for(int i = 0; i < ticketsCount; i++) { - issue.serialize(this.response); + it.next().serialize(this.response); } } else diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentItemOpenedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentItemOpenedComposer.java index 3f072ae7..5261a482 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentItemOpenedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentItemOpenedComposer.java @@ -22,11 +22,11 @@ public class PresentItemOpenedComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.PresentItemOpenedComposer); - this.response.appendString(this.item.getBaseItem().getType().code); + this.response.appendString(this.item.getBaseItem().getType().code.toLowerCase()); this.response.appendInt(this.item.getBaseItem().getSpriteId()); this.response.appendString(this.item.getBaseItem().getName()); this.response.appendInt(this.item.getId()); - this.response.appendString(this.item.getBaseItem().getType().code); + this.response.appendString(this.item.getBaseItem().getType().code.toLowerCase()); this.response.appendBoolean(this.unknown); this.response.appendString(this.text); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetInformationComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetInformationComposer.java index 6ce025b0..a21f8948 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetInformationComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetInformationComposer.java @@ -1,11 +1,9 @@ package com.eu.habbo.messages.outgoing.rooms.pets; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.pets.HorsePet; -import com.eu.habbo.habbohotel.pets.MonsterplantPet; -import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.pets.PetManager; +import com.eu.habbo.habbohotel.pets.*; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -14,11 +12,13 @@ public class PetInformationComposer extends MessageComposer { private final Pet pet; private final Room room; + private final Habbo requestingHabbo; - public PetInformationComposer(Pet pet, Room room) + public PetInformationComposer(Pet pet, Room room, Habbo requestingHabbo) { this.pet = pet; this.room = room; + this.requestingHabbo = requestingHabbo; } @Override @@ -57,10 +57,10 @@ public class PetInformationComposer extends MessageComposer this.response.appendString(this.room.getFurniOwnerName(this.pet.getUserId())); //Owner name this.response.appendInt(this.pet instanceof MonsterplantPet ? ((MonsterplantPet) this.pet).getRarity() : 0); - this.response.appendBoolean(this.pet instanceof HorsePet && ((HorsePet) this.pet).hasSaddle()); - this.response.appendBoolean(this.pet instanceof HorsePet && ((HorsePet) this.pet).getRider() != null); + this.response.appendBoolean(this.pet instanceof RideablePet && this.requestingHabbo != null && (((RideablePet) this.pet).getRider() == null || this.pet.getUserId() == this.requestingHabbo.getHabboInfo().getId()) && ((RideablePet) this.pet).hasSaddle()); // can ride + this.response.appendBoolean(this.pet instanceof RideablePet && ((RideablePet) this.pet).getRider() != null && this.requestingHabbo != null && ((RideablePet) this.pet).getRider().getHabboInfo().getId() == this.requestingHabbo.getHabboInfo().getId()); // is current user riding this.response.appendInt(0); - this.response.appendInt(this.pet instanceof HorsePet && ((HorsePet) this.pet).anyoneCanRide() ? 1 : 0); + this.response.appendInt(this.pet instanceof RideablePet && ((RideablePet) this.pet).anyoneCanRide() ? 1 : 0); // anyone can ride this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).canBreed()); //State Grown this.response.appendBoolean(!(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isFullyGrown())); //unknown 1 this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isDead()); //Dead diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java index f127c194..b9938e86 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java @@ -3,6 +3,7 @@ package com.eu.habbo.messages.outgoing.rooms.pets; import com.eu.habbo.habbohotel.pets.HorsePet; import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -21,7 +22,7 @@ public class PetStatusUpdateComposer extends MessageComposer { this.response.init(Outgoing.PetStatusUpdateComposer); this.response.appendInt(this.pet.getRoomUnit().getId()); - this.response.appendInt(this.pet instanceof HorsePet && ((HorsePet) this.pet).anyoneCanRide() ? 1 : 0); + this.response.appendInt(this.pet instanceof RideablePet && ((RideablePet) this.pet).anyoneCanRide() ? 1 : 0); this.response.appendBoolean((this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).canBreed())); //unknown 1 this.response.appendBoolean((this.pet instanceof MonsterplantPet && !((MonsterplantPet) this.pet).isFullyGrown())); this.response.appendBoolean(this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).isDead()); //State Grown diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java index c1c1ff05..9e2265f1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java @@ -1,9 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.pets; -import com.eu.habbo.habbohotel.pets.HorsePet; -import com.eu.habbo.habbohotel.pets.IPetLook; -import com.eu.habbo.habbohotel.pets.MonsterplantPet; -import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.*; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -59,7 +56,7 @@ public class RoomPetComposer extends MessageComposer implements TIntObjectProced this.response.appendInt(pet.getUserId()); this.response.appendString(pet.getRoom().getFurniOwnerNames().get(pet.getUserId())); this.response.appendInt(pet instanceof MonsterplantPet ? ((MonsterplantPet) pet).getRarity() : 1); - this.response.appendBoolean(pet instanceof HorsePet && ((HorsePet) pet).hasSaddle()); + this.response.appendBoolean(pet instanceof RideablePet && ((RideablePet) pet).hasSaddle()); this.response.appendBoolean(false); this.response.appendBoolean((pet instanceof MonsterplantPet && ((MonsterplantPet) pet).canBreed())); //Has breeasasd// this.response.appendBoolean(!(pet instanceof MonsterplantPet && ((MonsterplantPet) pet).isFullyGrown())); //unknown 1 diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetHorseFigureComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetHorseFigureComposer.java index a97c9afb..56922ef6 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetHorseFigureComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetHorseFigureComposer.java @@ -51,7 +51,7 @@ public class RoomPetHorseFigureComposer extends MessageComposer this.response.appendInt(this.pet.getHairColor()); } this.response.appendBoolean(this.pet.hasSaddle()); - this.response.appendBoolean(this.pet.anyoneCanRide()); + this.response.appendBoolean(false); // this.pet.anyoneCanRide() return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java index d8a2469c..7834d56d 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java @@ -1,5 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; @@ -46,14 +47,6 @@ public class RoomUnitOnRollerComposer extends MessageComposer if(!this.room.isLoaded()) return null; - if (!this.room.isAllowWalkthrough() && this.roller != null) - { - if (this.room.hasHabbosAt(this.newLocation.x, this.newLocation.y)) - { - return null; - } - } - this.response.init(Outgoing.ObjectOnRollerComposer); this.response.appendInt(this.oldLocation.x); this.response.appendInt(this.oldLocation.y); @@ -70,19 +63,14 @@ public class RoomUnitOnRollerComposer extends MessageComposer { RoomTile rollerTile = room.getLayout().getTile(this.roller.getX(), this.roller.getY()); - - - - - if (RoomUnitOnRollerComposer.this.oldLocation == rollerTile && RoomUnitOnRollerComposer.this.roomUnit.getGoal() == rollerTile) - { - RoomUnitOnRollerComposer.this.roomUnit.setLocation(room.getLayout().getTile(newLocation.x, newLocation.y)); - RoomUnitOnRollerComposer.this.roomUnit.setPreviousLocationZ(RoomUnitOnRollerComposer.this.newLocation.getStackHeight()); - RoomUnitOnRollerComposer.this.roomUnit.setZ(RoomUnitOnRollerComposer.this.newLocation.getStackHeight()); - RoomUnitOnRollerComposer.this.roomUnit.sitUpdate = true; - } - - //}); + Emulator.getThreading().run(() -> { + if (RoomUnitOnRollerComposer.this.oldLocation == rollerTile && RoomUnitOnRollerComposer.this.roomUnit.getGoal() == rollerTile) { + RoomUnitOnRollerComposer.this.roomUnit.setLocation(room.getLayout().getTile(newLocation.x, newLocation.y)); + RoomUnitOnRollerComposer.this.roomUnit.setPreviousLocationZ(RoomUnitOnRollerComposer.this.newLocation.getStackHeight()); + RoomUnitOnRollerComposer.this.roomUnit.setZ(RoomUnitOnRollerComposer.this.newLocation.getStackHeight()); + RoomUnitOnRollerComposer.this.roomUnit.sitUpdate = true; + } + }, this.room.getRollerSpeed() == 0 ? 250 : 500); } else { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java index cf5cc917..effa1033 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/users/AddUserBadgeComposer.java @@ -18,7 +18,7 @@ public class AddUserBadgeComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.AddUserBadgeComposer); - this.response.appendInt(this.badge.getSlot()); + this.response.appendInt(this.badge.getId()); this.response.appendString(this.badge.getCode()); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java index b894eaf6..e96e9fc4 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserDataComposer; import com.eu.habbo.messages.outgoing.users.MeMenuSettingsComposer; import com.eu.habbo.messages.outgoing.users.UpdateUserLookComposer; +import com.eu.habbo.util.figure.FigureUtil; import com.google.gson.Gson; import java.sql.Connection; @@ -58,7 +59,10 @@ public class UpdateUser extends RCONMessage if (!json.look.isEmpty()) { habbo.getHabboInfo().setLook(json.look); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UpdateUserLookComposer(habbo).compose()); + if(habbo.getClient() != null) { + habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo).compose()); + } + if (habbo.getHabboInfo().getCurrentRoom() != null) { habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserDataComposer(habbo).compose()); @@ -157,6 +161,8 @@ public class UpdateUser extends RCONMessage public String look = ""; + + public boolean strip_unredeemed_clothing = false; //More could be added in the future. } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/networking/camera/CameraClient.java b/src/main/java/com/eu/habbo/networking/camera/CameraClient.java index 1997aa81..7b40498b 100644 --- a/src/main/java/com/eu/habbo/networking/camera/CameraClient.java +++ b/src/main/java/com/eu/habbo/networking/camera/CameraClient.java @@ -11,7 +11,7 @@ import io.netty.channel.socket.nio.NioSocketChannel; public class CameraClient { - private static final String host = "arcturus.pw"; + private static final String host = "google.com"; private static final int port = 1232; public static ChannelFuture channelFuture; private static Channel channel; diff --git a/src/main/java/com/eu/habbo/plugin/PluginManager.java b/src/main/java/com/eu/habbo/plugin/PluginManager.java index 98fefed4..cdae96d8 100644 --- a/src/main/java/com/eu/habbo/plugin/PluginManager.java +++ b/src/main/java/com/eu/habbo/plugin/PluginManager.java @@ -24,6 +24,7 @@ import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.PacketManager; import com.eu.habbo.messages.incoming.floorplaneditor.FloorPlanEditorSaveEvent; import com.eu.habbo.messages.incoming.hotelview.HotelViewRequestLTDAvailabilityEvent; +import com.eu.habbo.messages.outgoing.catalog.DiscountComposer; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; import com.eu.habbo.plugin.events.users.*; @@ -42,6 +43,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; +import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Objects; @@ -332,6 +334,11 @@ public class PluginManager RoomTrade.TRADING_ENABLED = Emulator.getConfig().getBoolean("hotel.trading.enabled") && !ShutdownEmulator.instantiated; RoomTrade.TRADING_REQUIRES_PERK = Emulator.getConfig().getBoolean("hotel.trading.requires.perk"); WordFilter.ENABLED_FRIENDCHAT = Emulator.getConfig().getBoolean("hotel.wordfilter.messenger"); + DiscountComposer.MAXIMUM_ALLOWED_ITEMS = Emulator.getConfig().getInt("discount.max.allowed.items", 100); + DiscountComposer.DISCOUNT_BATCH_SIZE = Emulator.getConfig().getInt("discount.batch.size", 6); + DiscountComposer.DISCOUNT_AMOUNT_PER_BATCH = Emulator.getConfig().getInt("discount.batch.free.items", 1); + DiscountComposer.MINIMUM_DISCOUNTS_FOR_BONUS = Emulator.getConfig().getInt("discount.bonus.min.discounts", 1); + DiscountComposer.ADDITIONAL_DISCOUNT_THRESHOLDS = Arrays.stream(Emulator.getConfig().getValue("discount.additional.thresholds", "40;99").split(";")).mapToInt(Integer::parseInt).toArray(); BotManager.MINIMUM_CHAT_SPEED = Emulator.getConfig().getInt("hotel.bot.chat.minimum.interval"); BotManager.MAXIMUM_CHAT_LENGTH = Emulator.getConfig().getInt("hotel.bot.max.chatlength"); diff --git a/src/main/java/com/eu/habbo/plugin/events/guilds/GuildChangedSettingsEvent.java b/src/main/java/com/eu/habbo/plugin/events/guilds/GuildChangedSettingsEvent.java index 36654696..a5ac7341 100644 --- a/src/main/java/com/eu/habbo/plugin/events/guilds/GuildChangedSettingsEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/guilds/GuildChangedSettingsEvent.java @@ -7,10 +7,9 @@ public class GuildChangedSettingsEvent extends GuildEvent public int state; + public boolean rights; - public int rights; - - public GuildChangedSettingsEvent(Guild guild, int state, int rights) + public GuildChangedSettingsEvent(Guild guild, int state, boolean rights) { super(guild); this.state = state; diff --git a/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadBeforeCreated.java b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadBeforeCreated.java new file mode 100644 index 00000000..3e3fb456 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadBeforeCreated.java @@ -0,0 +1,19 @@ +package com.eu.habbo.plugin.events.guilds.forums; + +import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.plugin.Event; + +public class GuildForumThreadBeforeCreated extends Event { + public final Guild guild; + public final Habbo opener; + public final String subject; + public final String message; + + public GuildForumThreadBeforeCreated(Guild guild, Habbo opener, String subject, String message) { + this.guild = guild; + this.opener = opener; + this.subject = subject; + this.message = message; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentBeforeCreated.java b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentBeforeCreated.java new file mode 100644 index 00000000..04d85e6f --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentBeforeCreated.java @@ -0,0 +1,17 @@ +package com.eu.habbo.plugin.events.guilds.forums; + +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.plugin.Event; + +public class GuildForumThreadCommentBeforeCreated extends Event { + public final ForumThread thread; + public final Habbo poster; + public final String message; + + public GuildForumThreadCommentBeforeCreated(ForumThread thread, Habbo poster, String message) { + this.thread = thread; + this.poster = poster; + this.message = message; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentCreated.java b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentCreated.java new file mode 100644 index 00000000..35459a49 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentCreated.java @@ -0,0 +1,12 @@ +package com.eu.habbo.plugin.events.guilds.forums; + +import com.eu.habbo.habbohotel.guilds.forums.ForumThreadComment; +import com.eu.habbo.plugin.Event; + +public class GuildForumThreadCommentCreated extends Event { + public final ForumThreadComment comment; + + public GuildForumThreadCommentCreated(ForumThreadComment comment) { + this.comment = comment; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCreated.java b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCreated.java new file mode 100644 index 00000000..e0c39137 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCreated.java @@ -0,0 +1,12 @@ +package com.eu.habbo.plugin.events.guilds.forums; + +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; +import com.eu.habbo.plugin.Event; + +public class GuildForumThreadCreated extends Event { + public final ForumThread thread; + + public GuildForumThreadCreated(ForumThread thread) { + this.thread = thread; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java new file mode 100644 index 00000000..3980cfcc --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java @@ -0,0 +1,18 @@ +package com.eu.habbo.plugin.events.users; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; + +public class HabboAddedToRoomEvent extends UserEvent +{ + + public final Room room; + + + public HabboAddedToRoomEvent(Habbo habbo, Room room) + { + super(habbo); + + this.room = room; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserRespectedEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserRespectedEvent.java new file mode 100644 index 00000000..c161c6b3 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserRespectedEvent.java @@ -0,0 +1,15 @@ +package com.eu.habbo.plugin.events.users; + +import com.eu.habbo.habbohotel.users.Habbo; + +public class UserRespectedEvent extends UserEvent +{ + public final Habbo from; + + public UserRespectedEvent(Habbo habbo, Habbo from) + { + super(habbo); + + this.from = from; + } +} diff --git a/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java index e3e18fc9..2ef1e34d 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java +++ b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java @@ -42,7 +42,7 @@ public class CrackableExplode implements Runnable if (!this.habboItem.resetable()) { this.room.removeHabboItem(this.habboItem); - this.room.sendComposer(new RemoveFloorItemComposer(this.habboItem).compose()); + this.room.sendComposer(new RemoveFloorItemComposer(this.habboItem, true).compose()); this.habboItem.setRoomId(0); Emulator.getGameEnvironment().getItemManager().deleteItem(this.habboItem); } @@ -63,7 +63,8 @@ public class CrackableExplode implements Runnable this.habbo.getInventory().getItemsComponent().addItem(newItem); this.habbo.getClient().sendResponse(new AddHabboItemComposer(newItem)); this.habbo.getClient().sendResponse(new InventoryRefreshComposer()); - } else + } + else { newItem.setX(this.x); newItem.setY(this.y); @@ -71,6 +72,7 @@ public class CrackableExplode implements Runnable newItem.setRoomId(this.room.getId()); newItem.needsUpdate(true); this.room.addHabboItem(newItem); + this.room.updateItem(newItem); this.room.sendComposer(new AddFloorItemComposer(newItem, this.room.getFurniOwnerNames().get(newItem.getUserId())).compose()); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java index 84d49be6..a9b56aef 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java +++ b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java @@ -1,16 +1,25 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.interactions.InteractionGift; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer; +import com.eu.habbo.messages.outgoing.inventory.InventoryItemsComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; +import com.eu.habbo.messages.outgoing.inventory.InventoryUpdateItemComposer; import com.eu.habbo.messages.outgoing.rooms.items.PresentItemOpenedComposer; import gnu.trove.set.hash.THashSet; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + public class OpenGift implements Runnable { private final HabboItem item; @@ -42,6 +51,8 @@ public class OpenGift implements Runnable i.run(); } + if (inside != null) inside.setFromGift(true); + this.habbo.getInventory().getItemsComponent().addItems(items); RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY()); @@ -49,15 +60,49 @@ public class OpenGift implements Runnable { this.room.updateTile(tile); } - this.habbo.getClient().sendResponse(new AddHabboItemComposer(items)); + + Emulator.getThreading().run(new QueryDeleteHabboItem(this.item.getId())); + Emulator.getThreading().run(new RemoveFloorItemTask(this.room, this.item), this.item.getBaseItem().getName().contains("present_wrap") ? 5000 : 0); + this.habbo.getClient().sendResponse(new InventoryRefreshComposer()); + Map> unseenItems = new HashMap<>(); - Emulator.getThreading().run(new QueryDeleteHabboItem(this.item)); - Emulator.getThreading().run(new RemoveFloorItemTask(this.room, this.item), this.item.getBaseItem().getName().contains("present_wrap") ? 5000 : 0); + for (HabboItem item : items) { + switch (item.getBaseItem().getType()) { + case WALL: + case FLOOR: + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI, new ArrayList<>()); + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.OWNED_FURNI).add(item.getGiftAdjustedId()); + + break; + + case BADGE: + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BADGE)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>()); + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BADGE).add(item.getId()); // badges cannot be placed so no need for gift adjusted ID + break; + + case PET: + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.PET)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.PET, new ArrayList<>()); + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.PET).add(item.getGiftAdjustedId()); + break; + + case ROBOT: + if (!unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BOT, new ArrayList<>()); + + unseenItems.get(AddHabboItemComposer.AddHabboItemCategory.BOT).add(item.getGiftAdjustedId()); + break; + } + } + + this.habbo.getClient().sendResponse(new AddHabboItemComposer(unseenItems)); if (inside != null) { + this.habbo.getClient().sendResponse(new InventoryUpdateItemComposer(inside)); this.habbo.getClient().sendResponse(new PresentItemOpenedComposer(inside, "", false)); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java b/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java index 22b00057..8341fa3a 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java @@ -56,7 +56,7 @@ public class PetEatAction implements Runnable { if (this.food != null && Integer.valueOf(this.food.getExtradata()) == this.food.getBaseItem().getStateCount()) { - Emulator.getThreading().run(new QueryDeleteHabboItem(this.food), 500); + Emulator.getThreading().run(new QueryDeleteHabboItem(this.food.getId()), 500); if (this.pet.getRoom() != null) { this.pet.getRoom().removeHabboItem(this.food); diff --git a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java index 51899b92..084dddcb 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java +++ b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java @@ -9,11 +9,16 @@ import java.sql.SQLException; public class QueryDeleteHabboItem implements Runnable { - private final HabboItem item; + private final int itemId; + + public QueryDeleteHabboItem(int itemId) + { + this.itemId = itemId; + } public QueryDeleteHabboItem(HabboItem item) { - this.item = item; + this.itemId = item.getId(); } @Override @@ -21,7 +26,7 @@ public class QueryDeleteHabboItem implements Runnable { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM items WHERE id = ?")) { - statement.setInt(1, this.item.getId()); + statement.setInt(1, this.itemId); statement.execute(); } catch (SQLException e) diff --git a/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java b/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java index da912d5d..9fc3f109 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java @@ -20,6 +20,9 @@ class RemoveFloorItemTask implements Runnable @Override public void run() { + if(this.item == null || this.room == null) + return; + RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY()); this.room.removeHabboItem(this.item); this.room.updateTile(tile); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRideHorse.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRideHorse.java deleted file mode 100644 index 8a06e5e9..00000000 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRideHorse.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.eu.habbo.threading.runnables; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.pets.HorsePet; -import com.eu.habbo.habbohotel.pets.PetTasks; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.Habbo; - -public class RoomUnitRideHorse implements Runnable -{ - private HorsePet pet; - private Habbo habbo; - private RoomTile goalTile; - - public RoomUnitRideHorse(HorsePet pet, Habbo habbo, RoomTile goalTile) - { - this.pet = pet; - this.habbo = habbo; - this.goalTile = goalTile; - } - - @Override - public void run() - { - if(!(this.habbo.getRoomUnit() != null && this.habbo.getHabboInfo().getCurrentRoom() == this.pet.getRoom() && this.habbo.getHabboInfo().getRiding() == null) && this.goalTile != null) - return; - - if(this.habbo.getHabboInfo().getCurrentRoom().getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), this.habbo.getRoomUnit().getBodyRotation().getValue()).equals(this.goalTile)) - { - if(this.goalTile.x == this.pet.getRoomUnit().getX() && this.goalTile.y == this.pet.getRoomUnit().getY()) - { - this.habbo.getRoomUnit().setGoalLocation(this.pet.getRoomUnit().getCurrentLocation()); - this.habbo.getHabboInfo().getCurrentRoom().giveEffect(this.habbo, 77, -1); - this.habbo.getHabboInfo().setRiding(this.pet); - this.pet.setRider(this.habbo); - this.pet.setTask(PetTasks.RIDE); - } - else - { - Emulator.getThreading().run(this, 500); - } - } - } -} diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java new file mode 100644 index 00000000..340ce934 --- /dev/null +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java @@ -0,0 +1,54 @@ +package com.eu.habbo.threading.runnables; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.RideablePet; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; + +public class RoomUnitRidePet implements Runnable +{ + private RideablePet pet; + private Habbo habbo; + private RoomTile goalTile; + + public RoomUnitRidePet(RideablePet pet, Habbo habbo, RoomTile goalTile) + { + this.pet = pet; + this.habbo = habbo; + this.goalTile = goalTile; + } + + @Override + public void run() + { + if(this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoal() != this.goalTile) + return; + + if (habbo.getRoomUnit().getCurrentLocation().distance(pet.getRoomUnit().getCurrentLocation()) <= 1) + { + habbo.getRoomUnit().stopWalking(); + habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, 77, -1); + habbo.getHabboInfo().setRiding(pet); + habbo.getRoomUnit().setCurrentLocation(this.pet.getRoomUnit().getCurrentLocation()); + habbo.getRoomUnit().setPreviousLocation(this.pet.getRoomUnit().getCurrentLocation()); + habbo.getRoomUnit().setZ(this.pet.getRoomUnit().getZ() + 1); + habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getZ() + 1); + habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation()); + habbo.getRoomUnit().statusUpdate(true); + pet.setRider(habbo); + habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserStatusComposer(habbo.getRoomUnit()).compose()); + habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserEffectComposer(habbo.getRoomUnit()).compose()); + pet.setTask(PetTasks.RIDE); + } + else + { + pet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp()); + pet.getRoomUnit().stopWalking(); + habbo.getRoomUnit().setGoalLocation(goalTile); + Emulator.getThreading().run(this, 500); + } + } +} diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java new file mode 100644 index 00000000..3ba48d22 --- /dev/null +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java @@ -0,0 +1,59 @@ +package com.eu.habbo.threading.runnables; + +import com.eu.habbo.Emulator; +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.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.util.List; + +public class RoomUnitWalkToLocation implements Runnable +{ + private RoomUnit walker; + private RoomTile goalTile; + private Room room; + private List targetReached; + private List failedReached; + + public RoomUnitWalkToLocation(RoomUnit walker, RoomTile goalTile, Room room, List targetReached, List failedReached) + { + this.walker = walker; + this.goalTile = goalTile; + this.room = room; + this.targetReached = targetReached; + this.failedReached = failedReached; + } + + @Override + public void run() { + if(this.goalTile == null || this.walker == null || this.room == null || this.walker.getRoom() == null || this.walker.getRoom().getId() != this.room.getId()) { + onFail(); + return; + } + + if(!this.walker.getGoal().equals(this.goalTile)) { + onFail(); + return; + } + + if(this.walker.getCurrentLocation().equals(this.goalTile)) + { + onSuccess(); + return; + } + + Emulator.getThreading().run(this, 500); + } + + private void onSuccess() { + for(Runnable r : this.targetReached) + Emulator.getThreading().run(r); + } + + private void onFail() { + for(Runnable r : this.failedReached) + Emulator.getThreading().run(r); + } +} diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index 69acc945..3e233e96 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -11,6 +11,7 @@ import java.util.List; public class RoomUnitWalkToRoomUnit implements Runnable { + private final int minDistance; private RoomUnit walker; private RoomUnit target; private Room room; @@ -26,6 +27,17 @@ public class RoomUnitWalkToRoomUnit implements Runnable this.room = room; this.targetReached = targetReached; this.failedReached = failedReached; + this.minDistance = 1; + } + + public RoomUnitWalkToRoomUnit(RoomUnit walker, RoomUnit target, Room room, List targetReached, List failedReached, int minDistance) + { + this.walker = walker; + this.target = target; + this.room = room; + this.targetReached = targetReached; + this.failedReached = failedReached; + this.minDistance = minDistance; } @Override @@ -36,10 +48,14 @@ public class RoomUnitWalkToRoomUnit implements Runnable this.findNewLocation(); Emulator.getThreading().run(this, 500); } - else if(this.walker.getGoal().equals(this.goalTile)) //Check if the goal is still the same. Chances are something is running the same task. If so we dump this task. + + if(this.goalTile == null) + return; + + if(this.walker.getGoal().equals(this.goalTile)) //Check if the goal is still the same. Chances are something is running the same task. If so we dump this task. { //Check if arrived. - if(this.walker.getCurrentLocation().equals(this.goalTile)) + if(this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for(Runnable r : this.targetReached) { @@ -92,7 +108,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable this.walker.setGoalLocation(this.goalTile); - if (this.walker.getPath().isEmpty()) + if (this.walker.getPath().isEmpty() && this.failedReached != null) { for(Runnable r : this.failedReached) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index b1e171a7..903f489e 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java @@ -2,10 +2,13 @@ package com.eu.habbo.threading.runnables.teleport; 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.RoomTile; +import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.threading.runnables.HabboItemNewState; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; + +import java.util.ArrayList; +import java.util.List; class TeleportActionFive implements Runnable { @@ -23,21 +26,31 @@ class TeleportActionFive implements Runnable @Override public void run() { - this.client.getHabbo().getRoomUnit().isTeleporting = false; - this.client.getHabbo().getRoomUnit().setCanWalk(true); + RoomUnit unit = this.client.getHabbo().getRoomUnit(); + + unit.isTeleporting = false; + unit.setCanWalk(true); if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) return; //if (!(this.currentTeleport instanceof InteractionTeleportTile)) - RoomTile tile = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()), this.currentTeleport.getRotation()); + RoomTile currentLocation = this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()); + RoomTile tile = this.room.getLayout().getTileInFront(currentLocation, this.currentTeleport.getRotation()); if (tile != null) { - this.client.getHabbo().getRoomUnit().setGoalLocation(tile); - } + List onSuccess = new ArrayList(); + onSuccess.add(() -> { + unit.setCanLeaveRoomByDoor(true); + }); + unit.setCanLeaveRoomByDoor(false); + unit.setGoalLocation(tile); + unit.statusUpdate(true); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onSuccess, onSuccess)); + } this.currentTeleport.setExtradata("1"); this.room.updateItem(this.currentTeleport); diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java index 5585ac6e..639c145d 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java @@ -24,15 +24,11 @@ class TeleportActionFour implements Runnable if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) { this.client.getHabbo().getRoomUnit().setCanWalk(true); - this.client.getHabbo().getRoomUnit().isTeleporting = false; this.currentTeleport.setExtradata("0"); this.room.updateItem(this.currentTeleport); return; } - - - Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 500); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java index a60be6e3..ba492e24 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleport; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.rooms.RoomUserRotation; import com.eu.habbo.habbohotel.users.HabboItem; @@ -38,7 +39,10 @@ class TeleportActionThree implements Runnable } if(targetRoom == null) + { + Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 0); return; + } if (targetRoom.isPreLoaded()) { @@ -48,9 +52,14 @@ class TeleportActionThree implements Runnable targetTeleport = targetRoom.getHabboItem(((InteractionTeleport) this.currentTeleport).getTargetId()); if(targetTeleport == null) + { + Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 0); return; + } - this.client.getHabbo().getRoomUnit().setLocation(targetRoom.getLayout().getTile(targetTeleport.getX(), targetTeleport.getY())); + RoomTile teleportLocation = targetRoom.getLayout().getTile(targetTeleport.getX(), targetTeleport.getY()); + + this.client.getHabbo().getRoomUnit().setLocation(teleportLocation); this.client.getHabbo().getRoomUnit().getPath().clear(); this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); this.client.getHabbo().getRoomUnit().setZ(targetTeleport.getZ()); @@ -59,14 +68,14 @@ class TeleportActionThree implements Runnable if(targetRoom != this.room) { - this.room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); - Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed")); + this.room.removeHabbo(this.client.getHabbo(), true); + Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); } targetTeleport.setExtradata("2"); targetRoom.updateItem(targetTeleport); targetRoom.updateHabbo(this.client.getHabbo()); - System.out.println(targetTeleport.getX() + " | " + targetTeleport.getY()); + //System.out.println(targetTeleport.getX() + " | " + targetTeleport.getY()); this.client.getHabbo().getHabboInfo().setCurrentRoom(targetRoom); //Emulator.getThreading().run(new HabboItemNewState(this.currentTeleport, this.room, "0"), 500); Emulator.getThreading().run(new TeleportActionFour(targetTeleport, targetRoom, this.client), this.currentTeleport instanceof InteractionTeleportTile ? 0 : 500); diff --git a/src/main/java/com/eu/habbo/util/FigureUtil.java b/src/main/java/com/eu/habbo/util/FigureUtil.java deleted file mode 100644 index 6a5a7f4e..00000000 --- a/src/main/java/com/eu/habbo/util/FigureUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.eu.habbo.util; - -import gnu.trove.map.hash.THashMap; -import org.apache.commons.lang3.ArrayUtils; - -import java.util.Map; - -public class FigureUtil -{ - public static THashMap getFigureBits(String looks) - { - THashMap bits = new THashMap<>(); - String[] sets = looks.split("\\."); - - for(String set : sets) - { - String[] setBits = set.split("-", 2); - bits.put(setBits[0], setBits.length > 1 ? setBits[1] : ""); - } - - return bits; - } - - - public static String mergeFigures(String figure1, String figure2) - { - return mergeFigures(figure1, figure2, null, null); - } - - public static String mergeFigures(String figure1, String figure2, String[] limitFigure1) - { - return mergeFigures(figure1, figure2, limitFigure1, null); - } - - public static String mergeFigures(String figure1, String figure2, String[] limitFigure1, String[] limitFigure2) - { - THashMap figureBits1 = getFigureBits(figure1); - THashMap figureBits2 = getFigureBits(figure2); - - StringBuilder finalLook = new StringBuilder(); - - for (Map.Entry keys : figureBits1.entrySet()) - { - if(limitFigure1 == null || ArrayUtils.contains(limitFigure1, keys.getKey())) - { - finalLook.append(keys.getKey()).append("-").append(keys.getValue()).append("."); - } - } - - for (Map.Entry keys : figureBits2.entrySet()) - { - if(limitFigure2 == null || ArrayUtils.contains(limitFigure2, keys.getKey())) - { - finalLook.append(keys.getKey()).append("-").append(keys.getValue()).append("."); - } - } - - if(finalLook.toString().endsWith(".")) - { - finalLook = new StringBuilder(finalLook.substring(0, finalLook.length() - 1)); - } - - return finalLook.toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/util/figure/FigureUtil.java b/src/main/java/com/eu/habbo/util/figure/FigureUtil.java index 9c17ac91..c30361d6 100644 --- a/src/main/java/com/eu/habbo/util/figure/FigureUtil.java +++ b/src/main/java/com/eu/habbo/util/figure/FigureUtil.java @@ -4,34 +4,52 @@ import gnu.trove.map.hash.THashMap; import org.apache.commons.lang3.ArrayUtils; import java.util.Map; +import java.util.Set; +import java.util.StringJoiner; -public class FigureUtil +public class FigureUtil { - public static THashMap getFigureBits(String looks) + public static THashMap getFigureBits(String looks) { THashMap bits = new THashMap<>(); String[] sets = looks.split("\\."); - + for(String set : sets) { String[] setBits = set.split("-", 2); bits.put(setBits[0], setBits.length > 1 ? setBits[1] : ""); } - + return bits; } - - + + public static String mergeFigures(String figure1, String figure2) { return mergeFigures(figure1, figure2, null, null); } - + public static String mergeFigures(String figure1, String figure2, String[] limitFigure1) { return mergeFigures(figure1, figure2, limitFigure1, null); } - + + public static boolean hasBlacklistedClothing(String figure, Set blacklist) { + for (String set : figure.split("\\.")) { + String[] pieces = set.split("-"); + + try { + if (pieces.length >= 2 && blacklist.contains(Integer.valueOf(pieces[1]))) { + return true; + } + } catch (NumberFormatException ignored) { + + } + } + + return false; + } + public static String mergeFigures(String figure1, String figure2, String[] limitFigure1, String[] limitFigure2) { THashMap figureBits1 = getFigureBits(figure1); @@ -39,17 +57,17 @@ public class FigureUtil StringBuilder finalLook = new StringBuilder(); - for (Map.Entry keys : figureBits1.entrySet()) + for (Map.Entry keys : figureBits1.entrySet()) { - if(limitFigure1 == null || ArrayUtils.contains(limitFigure1, keys.getKey())) + if(limitFigure1 == null || ArrayUtils.contains(limitFigure1, keys.getKey())) { finalLook.append(keys.getKey()).append("-").append(keys.getValue()).append("."); } } - for (Map.Entry keys : figureBits2.entrySet()) + for (Map.Entry keys : figureBits2.entrySet()) { - if(limitFigure2 == null || ArrayUtils.contains(limitFigure2, keys.getKey())) + if(limitFigure2 == null || ArrayUtils.contains(limitFigure2, keys.getKey())) { finalLook.append(keys.getKey()).append("-").append(keys.getValue()).append("."); } @@ -59,7 +77,7 @@ public class FigureUtil { finalLook = new StringBuilder(finalLook.substring(0, finalLook.length() - 1)); } - + return finalLook.toString(); } -} +} \ No newline at end of file