From 4c279172732daaa85396fd9237207cd943d180be Mon Sep 17 00:00:00 2001 From: necmi <183-necmi@users.noreply.git.krews.org> Date: Fri, 10 Jul 2020 21:18:45 -0400 Subject: [PATCH] Refactored bot wired. --- .../wired/effects/WiredEffectBotClothes.java | 9 +++--- .../effects/WiredEffectBotFollowHabbo.java | 19 ++++++------ .../effects/WiredEffectBotGiveHandItem.java | 25 +++++++--------- .../wired/effects/WiredEffectBotTalk.java | 17 +++++++---- .../effects/WiredEffectBotTalkToHabbo.java | 17 ++++++----- .../wired/effects/WiredEffectBotTeleport.java | 29 +++++++++--------- .../effects/WiredEffectBotWalkToFurni.java | 30 ++++++++----------- 7 files changed, 72 insertions(+), 74 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java index 9082ba12..ec22bf63 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java @@ -68,12 +68,13 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { List bots = room.getBots(this.botName); - if (bots.size() > 1) { + + if (bots.size() != 1) { return false; } - for (Bot bot : bots) { - bot.setFigure(this.botLook); - } + + Bot bot = bots.get(0); + bot.setFigure(this.botLook); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java index cf46e5ff..928068af 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java @@ -86,16 +86,15 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { Habbo habbo = room.getHabbo(roomUnit); - if (habbo != null) { - List bots = room.getBots(this.botName); - if (bots.size() > 1) { - return false; - } - for (Bot bot : bots) { - if (this.mode == 1) - bot.startFollowingHabbo(habbo); - else - bot.stopFollowingHabbo(); + List bots = room.getBots(this.botName); + + if (habbo != null && bots.size() == 1) { + Bot bot = bots.get(0); + + if (this.mode == 1) { + bot.startFollowingHabbo(habbo); + } else { + bot.stopFollowingHabbo(); } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index d8f03705..94173cdd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -88,24 +88,21 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { Habbo habbo = room.getHabbo(roomUnit); + List bots = room.getBots(this.botName); - if (habbo != null) { - List bots = room.getBots(this.botName); - if (bots.size() > 1) { - return false; - } - for (Bot bot : bots) { - List tasks = new ArrayList<>(); - tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId)); - tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); + if (habbo != null && bots.size() == 1) { + Bot bot = bots.get(0); - Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); + List tasks = new ArrayList<>(); + tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId)); + tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); - List failedReach = new ArrayList<>(); - failedReach.add(() -> tasks.forEach(Runnable::run)); + Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach)); - } + List failedReach = new ArrayList<>(); + failedReach.add(() -> tasks.forEach(Runnable::run)); + + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach)); return true; } 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 b8f95349..e73978a0 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 @@ -83,16 +83,21 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { .replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "") .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + ""); } + List bots = room.getBots(this.botName); - if (bots.size() > 1) { + + if (bots.size() != 1) { return false; } - for (Bot bot : bots) { - if (this.mode == 1) - bot.shout(message); - else - bot.talk(message); + + Bot bot = bots.get(0); + + if (this.mode == 1) { + bot.shout(message); + } else { + bot.talk(message); } + return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java index 7e90eb02..aec24c88 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java @@ -103,19 +103,22 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + ""); List bots = room.getBots(this.botName); - if (bots.size() > 1) { + + if (bots.size() != 1) { return false; } - for (Bot bot : bots) { - if (this.mode == 1) { - bot.whisper(m, habbo); - } else { - bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); - } + + Bot bot = bots.get(0); + + if (this.mode == 1) { + bot.whisper(m, habbo); + } else { + bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); } return true; } + return false; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java index 7920c8d2..b88e7877 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java @@ -139,23 +139,22 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { List bots = room.getBots(this.botName); - if (bots.isEmpty()) - return false; - - if (bots.size() > 1) { + if (bots.size() != 1) { return false; } - 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) { - teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY())); - return true; - } else { - j++; - } + + Bot bot = bots.get(0); + + int i = Emulator.getRandom().nextInt(this.items.size()) + 1; + int j = 1; + + for (HabboItem item : this.items) { + if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) { + if (i == j) { + teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY())); + return true; + } else { + j++; } } } 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 484e9fca..1b0efe08 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 @@ -88,14 +88,13 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.items.isEmpty()) - return false; - List bots = room.getBots(this.botName); - if (bots.isEmpty()) + if (this.items.isEmpty() || bots.size() != 1) { return false; + } + Bot bot = bots.get(0); THashSet items = new THashSet<>(); for (HabboItem item : this.items) { @@ -108,20 +107,15 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { } if (this.items.size() > 0) { - if (bots.size() > 1) { - return false; - } - 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++; - } + 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++; } } }