From 8716d42df9200f38e87db6fb944bc253a8978c90 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 07:21:43 +0100 Subject: [PATCH 001/118] Perfected horses and made RideablePet class - ability for other pets to be ridden through Plugin API --- .../items/interactions/InteractionNest.java | 38 +++++----- .../eu/habbo/habbohotel/pets/HorsePet.java | 52 ++----------- .../eu/habbo/habbohotel/pets/RideablePet.java | 53 +++++++++++++ .../com/eu/habbo/habbohotel/rooms/Room.java | 17 ----- .../eu/habbo/habbohotel/rooms/RoomLayout.java | 22 ++++++ .../eu/habbo/habbohotel/rooms/RoomUnit.java | 22 +++--- .../eu/habbo/habbohotel/users/HabboInfo.java | 51 ++++++++++++- .../com/eu/habbo/messages/PacketManager.java | 6 +- .../eu/habbo/messages/PacketManager_1006.java | 6 +- .../incoming/rooms/pets/HorseRideEvent.java | 76 ------------------- .../rooms/pets/HorseRideSettingsEvent.java | 28 ------- .../incoming/rooms/pets/PetPickupEvent.java | 9 +++ .../incoming/rooms/pets/PetRideEvent.java | 60 +++++++++++++++ .../rooms/pets/PetRideSettingsEvent.java | 37 +++++++++ ...UseItemEvent.java => PetUseItemEvent.java} | 2 +- .../rooms/pets/PetInformationComposer.java | 11 +-- .../rooms/pets/PetStatusUpdateComposer.java | 3 +- .../outgoing/rooms/pets/RoomPetComposer.java | 7 +- .../runnables/RoomUnitRideHorse.java | 44 ----------- .../threading/runnables/RoomUnitRidePet.java | 54 +++++++++++++ 20 files changed, 334 insertions(+), 264 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java delete mode 100644 src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideEvent.java delete mode 100644 src/main/java/com/eu/habbo/messages/incoming/rooms/pets/HorseRideSettingsEvent.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideEvent.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetRideSettingsEvent.java rename src/main/java/com/eu/habbo/messages/incoming/rooms/pets/{HorseUseItemEvent.java => PetUseItemEvent.java} (99%) delete mode 100644 src/main/java/com/eu/habbo/threading/runnables/RoomUnitRideHorse.java create mode 100644 src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java 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/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/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..ab111117 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,8 @@ 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.users.*; import com.eu.habbo.habbohotel.wired.*; import com.eu.habbo.messages.ISerialize; @@ -1569,21 +1567,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); 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..32d3d23a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -654,6 +654,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/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index ebeac176..89fa8feb 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; @@ -117,15 +117,15 @@ public class RoomUnit return false; } - Boolean isHorse = false; + Boolean isRiding = 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()) { + if(pet instanceof RideablePet) { + isRiding = true; + if (((RideablePet) pet).getRider() != null) { + if(!((RideablePet) pet).getRider().getRoomUnit().isWalking()) { this.status.remove(RoomUnitStatus.MOVE); - this.setCurrentLocation(((HorsePet) pet).getRider().getRoomUnit().getPreviousLocation()); + this.setCurrentLocation(((RideablePet) pet).getRider().getRoomUnit().getPreviousLocation()); if (this.status.remove(RoomUnitStatus.MOVE) != null) this.statusUpdate = true; } @@ -182,7 +182,7 @@ public class RoomUnit if (next != null && room.hasHabbosAt(next.x, next.y)) { - if(!isHorse) { + if(!isRiding) { return false; } } @@ -284,7 +284,7 @@ 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; } @@ -368,14 +368,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); } } } 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..9d7efde6 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,13 @@ 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 gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.procedure.TIntIntProcedure; @@ -14,6 +20,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 +48,7 @@ public class HabboInfo implements Runnable private Room currentRoom; private int roomQueueId; - private HorsePet riding; + private RideablePet riding; private Class currentGame; private TIntIntHashMap currencies; @@ -357,12 +365,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; } 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/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/PetPickupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java index 8cac95c8..19f5a6ed 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,6 +36,14 @@ 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; } + + if(pet instanceof RideablePet) { + RideablePet rideablePet = (RideablePet)pet; + if(rideablePet.getRider() != null) { + rideablePet.getRider().getHabboInfo().dismountPet(true); + } + } + room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); room.removePet(petId); pet.setRoomUnit(null); 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 99% 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..c94745b9 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 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..716c2783 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,10 +1,7 @@ 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.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -57,10 +54,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 && ((RideablePet) this.pet).hasSaddle()); + this.response.appendBoolean(this.pet instanceof RideablePet && ((RideablePet) this.pet).getRider() != null); 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); 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/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); + } + } +} From e5970cb993b244935d3597c38da3e72058a3f44e Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 07:40:24 +0100 Subject: [PATCH 002/118] Prevent pet training when rider on pet, if rider initiates training dismount --- .../com/eu/habbo/habbohotel/commands/CommandHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From 3deae81cd275aa15d315d146ea44d075397a741d Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 10:22:20 +0100 Subject: [PATCH 003/118] Teleport fixes. Fixed #16 and #1 + always correct location when entering room. --- .../InteractionHabboClubTeleportTile.java | 4 +- .../interactions/InteractionTeleport.java | 180 +++++++++++------- .../interactions/InteractionTeleportTile.java | 25 ++- .../habbo/habbohotel/rooms/RoomManager.java | 23 ++- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 7 +- .../runnables/RoomUnitWalkToLocation.java | 59 ++++++ .../teleport/TeleportActionFive.java | 9 +- .../teleport/TeleportActionFour.java | 4 - .../teleport/TeleportActionThree.java | 9 +- 9 files changed, 215 insertions(+), 105 deletions(-) create mode 100644 src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java 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/InteractionTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java index 4f1ebaf8..1dd5e11e 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,81 @@ 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); + }); + + onFail.add(() -> { + walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentLocation); + this.setExtradata("0"); + room.updateItem(this); + this.roomUnitID = -1; + }); + + walkable = true; + room.updateTile(currentLocation); + unit.setGoalLocation(currentLocation); + 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 +138,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 +167,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 +197,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/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 9e43752f..1ff0ce43 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -692,8 +692,22 @@ 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().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)) { @@ -732,11 +746,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,7 +802,7 @@ 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()); 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 89fa8feb..0f43d8f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -241,10 +241,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)) { this.room = room; this.findPath(); @@ -799,4 +798,8 @@ public class RoomUnit { return this.invisible; } + + public Room getRoom() { + return room; + } } 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/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index b1e171a7..fe8d268f 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,8 +2,7 @@ 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; @@ -31,11 +30,15 @@ class TeleportActionFive implements Runnable //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().setPreviousLocation(currentLocation); + this.client.getHabbo().getRoomUnit().setPreviousLocationZ(currentLocation.getStackHeight()); this.client.getHabbo().getRoomUnit().setGoalLocation(tile); + this.client.getHabbo().getRoomUnit().statusUpdate(true); } 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..fef0aa46 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; @@ -50,7 +51,9 @@ class TeleportActionThree implements Runnable if(targetTeleport == null) 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()); @@ -60,13 +63,13 @@ 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")); + 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); From 36a0f848d249b9a3480c58d1993a46750c14e5d7 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 10:46:04 +0100 Subject: [PATCH 004/118] Walk through fixed --- src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 32d3d23a..801377d8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -314,7 +314,7 @@ public class RoomLayout if (height > MAXIMUM_STEP_HEIGHT && currentAdj.state == RoomTileState.OPEN) continue; //Check if the tile has habbos. - if (!this.room.isAllowWalkthrough() && this.room.hasHabbosAt(currentAdj.x, currentAdj.y)) + if ((!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation)) && (this.room.hasHabbosAt(currentAdj.x, currentAdj.y) || this.room.hasPetsAt(currentAdj.x, currentAdj.y) || this.room.hasBotsAt(currentAdj.x, currentAdj.y))) { closedList.add(currentAdj); openList.remove(currentAdj); From 7a60b97ecd074a4f468f7cb4ae1047934abcc55c Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 11:15:45 +0100 Subject: [PATCH 005/118] Fixed horse to work with walk through --- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) 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 0f43d8f6..161284a1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -54,6 +54,7 @@ public class RoomUnit public int kickCount = 0; private boolean statusUpdate = false; private boolean invisible = false; + private boolean lastCycleStatus = false; private final ConcurrentHashMap status; private final THashMap cacheable; @@ -117,22 +118,32 @@ public class RoomUnit return false; } - Boolean isRiding = false; - Pet pet = room.getPet(this); - if(pet != null) { + Habbo rider = null; + if(this.getRoomUnitType() == RoomUnitType.PET) { + Pet pet = room.getPet(this); if(pet instanceof RideablePet) { - isRiding = true; - if (((RideablePet) pet).getRider() != null) { - if(!((RideablePet) pet).getRider().getRoomUnit().isWalking()) { - this.status.remove(RoomUnitStatus.MOVE); - this.setCurrentLocation(((RideablePet) pet).getRider().getRoomUnit().getPreviousLocation()); - if (this.status.remove(RoomUnitStatus.MOVE) != null) this.statusUpdate = true; - - } - } + 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) @@ -182,9 +193,7 @@ public class RoomUnit if (next != null && room.hasHabbosAt(next.x, next.y)) { - if(!isRiding) { - return false; - } + return false; } } @@ -283,10 +292,10 @@ public class RoomUnit double zHeight = 0.0D; - if (((habbo != null && habbo.getHabboInfo().getRiding() != null) || isRiding) && 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) { From bf26661bdc3e8790c7a13f5214bc4a3b8f7d9790 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 11:43:41 +0100 Subject: [PATCH 006/118] Pathfinder improved --- .../eu/habbo/habbohotel/rooms/RoomLayout.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) 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 801377d8..b46ea095 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.*; @@ -271,10 +274,24 @@ public class RoomLayout openList.add(oldTile.copy()); + List unitsAt = new ArrayList<>(); + + for(Bot b : this.room.getCurrentBots().valueCollection()) { + unitsAt.add(b.getRoomUnit().getCurrentLocation()); + } + + for(Habbo b : this.room.getCurrentHabbos().values()) { + unitsAt.add(b.getRoomUnit().getCurrentLocation()); + } + + for(Pet b : this.room.getCurrentPets().valueCollection()) { + unitsAt.add(b.getRoomUnit().getCurrentLocation()); + } + long startMillis = System.currentTimeMillis(); while (true) { - if (System.currentTimeMillis() - startMillis > 25) + if (System.currentTimeMillis() - startMillis > 50) { return new LinkedList<>(); } @@ -294,9 +311,7 @@ public class RoomLayout if (closedList.contains(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 +326,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() || currentAdj.equals(goalLocation)) && (this.room.hasHabbosAt(currentAdj.x, currentAdj.y) || this.room.hasPetsAt(currentAdj.x, currentAdj.y) || this.room.hasBotsAt(currentAdj.x, currentAdj.y))) + if (unitsAt.contains(currentAdj) && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { closedList.add(currentAdj); openList.remove(currentAdj); @@ -392,11 +407,14 @@ public class RoomLayout return null; RoomTile cheapest = openList.get(0); + int cheapestFcost = Integer.MAX_VALUE; for (RoomTile anOpenList : openList) { - if (anOpenList.getfCosts() < cheapest.getfCosts()) + int f = cheapest.getfCosts(); + if (anOpenList.getfCosts() < cheapestFcost) { cheapest = anOpenList; + cheapestFcost = f; } } return cheapest; From a692d2fbf0a82f06fadd888e4ef45ec35025260e Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 4 May 2019 21:41:18 +0100 Subject: [PATCH 007/118] Game timers fixed --- .../com/eu/habbo/habbohotel/games/Game.java | 79 +++-- .../games/battlebanzai/BattleBanzaiGame.java | 185 +++++----- .../habbohotel/games/freeze/FreezeGame.java | 88 ++--- .../habbohotel/games/wired/WiredGame.java | 38 +-- .../games/InteractionGameTimer.java | 317 +++++++++++------- .../com/eu/habbo/habbohotel/rooms/Room.java | 4 + .../habbo/habbohotel/rooms/RoomManager.java | 32 ++ .../habbohotel/rooms/RoomSpecialTypes.java | 37 -- .../eu/habbo/habbohotel/users/HabboItem.java | 4 + 9 files changed, 396 insertions(+), 388 deletions(-) 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..d052d2d9 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; @@ -170,32 +171,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; - this.endTime = Emulator.getIntUnixTimestamp(); - + public void onEnd() { this.saveScores(); GameTeam winningTeam = null; @@ -225,18 +201,55 @@ 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; + 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; + this.endTime = Emulator.getIntUnixTimestamp(); + + 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); - } } 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..224dc623 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,6 +14,8 @@ 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.map.hash.THashMap; @@ -35,8 +38,6 @@ public class BattleBanzaiGame extends Game public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock"); - private int timeLeft; - private int tileCount; private int countDown; @@ -62,22 +63,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 +81,6 @@ public class BattleBanzaiGame extends Game this.room.updateItemState(item); } - this.timeLeft = highestTime; - - if (this.timeLeft == 0) - { - this.timeLeft = 30; - } - this.start(); } @@ -150,99 +132,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); } } catch (Exception e) @@ -251,13 +184,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 +240,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(); 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..fb2ba5d8 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 @@ -45,8 +45,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,21 +57,8 @@ 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(); @@ -95,12 +80,6 @@ public class FreezeGame extends Game } } } - this.timeLeft = highestTime; - - if (this.timeLeft == 0) - { - this.timeLeft = 30; - } this.start(); } @@ -281,8 +260,7 @@ public class FreezeGame extends Game super.start(); this.refreshGates(); - - WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, this.room, null); + this.setFreezeTileState("1"); this.run(); } @@ -295,50 +273,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 +316,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/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/items/interactions/games/InteractionGameTimer.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java index e6dfd61e..8c8064d5 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,54 @@ public abstract class InteractionGameTimer extends HabboItem super(id, userId, item, extradata, limitedStack, limitedSells); } + @Override + public void run() { + if(this.needsUpdate() || this.needsDelete()) { + super.run(); + } + + 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) { + //end existing games + for (Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = InteractionGameTimer.getOrCreateGame(room, gameClass); + if (!game.state.equals(GameState.IDLE)) { + game.onEnd(); + game.stop(); + } + } + + WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[] { }); + } + @Override public void onPickUp(Room room) { @@ -52,8 +110,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 +123,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 +143,131 @@ 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); + boolean gamesActive = false; + for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) + { + if(timer.isRunning()) + gamesActive = true; + } + + if(gamesActive) { + //stop existing games + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + if(game.isRunning) { + game.stop(); + } + } + } + + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + if(!game.isRunning) { + game.start(); + } + } + + 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; + + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + if(this.isPaused) { + game.pause(); + } + else { + game.unpause(); + } + } + + if(!this.isPaused) { + Emulator.getThreading().run(this); + } + } + + if(!this.isRunning) { + for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { + Game game = getOrCreateGame(room, gameClass); + game.initialise(); + } + + WiredHandler.handle(WiredTriggerType.GAME_STARTS, null, room, new Object[] { }); + Emulator.getThreading().run(this); + } + + if(!this.isRunning) { + timeNow = this.baseTime; + this.isRunning = true; + room.updateItem(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 +280,30 @@ 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 { + System.out.println(gameClass.getName()); + 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 +318,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 +336,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/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index ab111117..4815d2cd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1013,6 +1013,10 @@ 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(); 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 1ff0ce43..65c04443 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,15 @@ 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.tag.TagGame; +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; @@ -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)"); } @@ -1760,4 +1780,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/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java index 126a74f7..68aa8ba2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java @@ -221,6 +221,10 @@ public abstract class HabboItem implements Runnable, IEventTriggers return this.needsUpdate; } + public boolean needsDelete() { + return needsDelete; + } + public void needsUpdate(boolean value) { this.needsUpdate = value; From b0cac91fb6c565794f62637dc7082e6dc1b8b31a Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 5 May 2019 03:51:27 +0100 Subject: [PATCH 008/118] Various game fixes --- .../com/eu/habbo/habbohotel/games/Game.java | 50 +++++----- .../games/battlebanzai/BattleBanzaiGame.java | 18 +--- .../battlebanzai/BattleBanzaiGameTeam.java | 13 ++- .../habbohotel/games/freeze/FreezeGame.java | 54 ++++------- .../games/freeze/FreezeGameTeam.java | 13 ++- .../games/InteractionGameGate.java | 12 +++ .../games/InteractionGameTimer.java | 55 ++++++----- .../gates/InteractionBattleBanzaiGate.java | 13 +-- .../freeze/gates/InteractionFreezeGate.java | 11 +-- .../wired/effects/WiredEffectBotTalk.java | 3 - .../wired/effects/WiredEffectTeleport.java | 91 +++++++++---------- 11 files changed, 156 insertions(+), 177 deletions(-) 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 d052d2d9..4e13453f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/Game.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/Game.java @@ -25,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; @@ -133,6 +124,7 @@ public abstract class Game implements Runnable } } + /* boolean deleteGame = true; for (GameTeam team : this.teams.values()) { @@ -147,6 +139,7 @@ public abstract class Game implements Runnable { this.room.deleteGame(this); } + */ } @@ -172,6 +165,8 @@ public abstract class Game implements Runnable } public void onEnd() { + this.endTime = Emulator.getIntUnixTimestamp(); + this.saveScores(); GameTeam winningTeam = null; @@ -214,7 +209,6 @@ public abstract class Game implements Runnable if (this.state.equals(GameState.RUNNING)) { this.state = GameState.PAUSED; - this.pauseTime = Emulator.getIntUnixTimestamp(); } } @@ -223,14 +217,12 @@ public abstract class Game implements Runnable 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; - this.endTime = Emulator.getIntUnixTimestamp(); boolean gamesActive = false; for(HabboItem timer : room.getFloorItems()) @@ -302,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 224dc623..f61002ff 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 @@ -175,7 +175,7 @@ public class BattleBanzaiGame extends Game timer.setRunning(false); } - InteractionGameTimer.endGames(room); + InteractionGameTimer.endGames(room, true); } } catch (Exception e) @@ -267,22 +267,6 @@ 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) { 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 fb2ba5d8..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; @@ -64,23 +65,6 @@ public class FreezeGame extends Game 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.start(); } @@ -96,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()) @@ -259,8 +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(); - + this.setFreezeTileState("1"); this.run(); } 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/items/interactions/games/InteractionGameGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java index ddca2a55..e5fc6212 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,13 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem super.serializeExtradata(serverMessage); } + + public void updateState(Game game, int maxPlayers) { + int 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 8c8064d5..81e6df9d 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 @@ -59,6 +59,9 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable super.run(); } + if(this.getRoomId() == 0) + return; + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if(room == null || !this.isRunning || this.isPaused) @@ -89,16 +92,26 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable } 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(); } } - WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[] { }); + if(triggerWired) { + WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); + } } @Override @@ -151,27 +164,12 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable // if wired triggered it if (objects.length >= 2 && objects[1] instanceof WiredEffectType && !this.isRunning) { - boolean gamesActive = false; - for(InteractionGameTimer timer : room.getRoomSpecialTypes().getGameTimers().values()) - { - if(timer.isRunning()) - gamesActive = true; - } - - if(gamesActive) { - //stop existing games - for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { - Game game = getOrCreateGame(room, gameClass); - if(game.isRunning) { - game.stop(); - } - } - } + endGamesIfLastTimer(room); for(Class gameClass : Emulator.getGameEnvironment().getRoomManager().getGameTypes()) { Game game = getOrCreateGame(room, gameClass); if(!game.isRunning) { - game.start(); + game.initialise(); } } @@ -196,13 +194,18 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable switch (state) { case 1: - 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(this.isPaused) { + if(allPaused) { game.pause(); } else { @@ -211,24 +214,26 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable } 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[] { }); - Emulator.getThreading().run(this); - } - - if(!this.isRunning) { - timeNow = this.baseTime; this.isRunning = true; + timeNow = this.baseTime; room.updateItem(this); + Emulator.getThreading().run(this); } break; 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/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/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/WiredEffectTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java index 72e24eef..11463890 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,50 @@ public class WiredEffectTeleport extends InteractionWiredEffect return true; } + public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { + Room room = roomUnit.getRoom(); + + // 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 +190,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; } From 122c646c13a7487d79b8a22f16f740746996b7c0 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 5 May 2019 05:21:02 +0100 Subject: [PATCH 009/118] Fixed pathfinder bug --- src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 b46ea095..7bd8f853 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -407,14 +407,11 @@ public class RoomLayout return null; RoomTile cheapest = openList.get(0); - int cheapestFcost = Integer.MAX_VALUE; for (RoomTile anOpenList : openList) { - int f = cheapest.getfCosts(); - if (anOpenList.getfCosts() < cheapestFcost) + if (anOpenList.getfCosts() < cheapest.getfCosts()) { cheapest = anOpenList; - cheapestFcost = f; } } return cheapest; From c44d8e8c8f12eb3ccd89112990001a13d57e12d2 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 5 May 2019 05:46:35 +0100 Subject: [PATCH 010/118] Fixed UpdatePetDataCommand --- .../eu/habbo/habbohotel/pets/PetManager.java | 62 ++++--------------- 1 file changed, 13 insertions(+), 49 deletions(-) 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); } } From b44d9439aaeade151c786265df175fcd09813c10 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 6 May 2019 05:23:51 +0100 Subject: [PATCH 011/118] Pets remove from room when Habbo leaves or if the setting is disabled --- .../com/eu/habbo/habbohotel/rooms/Room.java | 65 ++++++++++++++----- .../habbo/habbohotel/rooms/RoomManager.java | 4 -- 2 files changed, 49 insertions(+), 20 deletions(-) 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 4815d2cd..5b124022 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1023,6 +1023,8 @@ public class Room implements Comparable, ISerialize, Runnable } this.games.clear(); + removeAllPets(ownerId); + synchronized (this.roomItems) { TIntObjectIterator iterator = this.roomItems.iterator(); @@ -1086,22 +1088,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) @@ -2386,6 +2372,48 @@ 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.setRoom(null); + removedPets.add(pet); + this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); + + 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) @@ -3201,6 +3229,11 @@ public class Room implements Comparable, ISerialize, Runnable trade.stopTrade(habbo); } + if (habbo.getHabboInfo().getId() != this.ownerId) + { + this.pickupPetsForHabbo(habbo); + } + this.updateDatabaseUserCount(); } 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 65c04443..bb77a5e1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -1099,10 +1099,6 @@ public class RoomManager { habbo.getRoomUnit().setPathFinderRoom(null); - if (!room.isOwner(habbo)) - { - room.pickupPetsForHabbo(habbo); - } this.logExit(habbo); room.removeHabbo(habbo); From 74f4f0eb70ebb503fc37f27591f33eda4719c34a Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 6 May 2019 05:37:52 +0100 Subject: [PATCH 012/118] Fixed bugs with horse riding settings --- .../com/eu/habbo/habbohotel/commands/TestCommand.java | 2 +- .../rooms/pets/RequestPetInformationEvent.java | 2 +- .../outgoing/rooms/pets/PetInformationComposer.java | 11 +++++++---- .../rooms/pets/RoomPetHorseFigureComposer.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) 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/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/outgoing/rooms/pets/PetInformationComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetInformationComposer.java index 716c2783..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 @@ -3,6 +3,7 @@ package com.eu.habbo.messages.outgoing.rooms.pets; import com.eu.habbo.Emulator; 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; @@ -11,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 @@ -54,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 RideablePet && ((RideablePet) this.pet).hasSaddle()); - this.response.appendBoolean(this.pet instanceof RideablePet && ((RideablePet) 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 RideablePet && ((RideablePet) 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/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; } } From 56f1e0e54d7f7e47ccf085c5c5dd32abcd5bb836 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Tue, 7 May 2019 23:45:32 +0100 Subject: [PATCH 013/118] Bot Height is now fixed on placing on rooms with multiple z heights. Sitting is also fixed in the same regard --- .../java/com/eu/habbo/habbohotel/bots/BotManager.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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); From 1eda3d78fa6a83a7814d9b3bed57c985bd157dec Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Thu, 9 May 2019 02:01:31 +0100 Subject: [PATCH 014/118] Fixed hotel.room.rollers.norules. --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 5b124022..66afe4f9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1596,7 +1596,9 @@ public class Room implements Comparable, ISerialize, Runnable for(HabboItem item : getItemsAt(rollerTile)) { - itemsOnRoller.add(item); + if(item.getZ() >= roller.getZ() + roller.getBaseItem().getHeight()) { + itemsOnRoller.add(item); + } } itemsOnRoller.remove(roller); @@ -1612,7 +1614,6 @@ public class Room implements Comparable, ISerialize, Runnable if (tileInFront == null) return true; - if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y)) return true; @@ -1758,7 +1759,7 @@ public class Room implements Comparable, ISerialize, Runnable messages.clear(); } - if ((allowFurniture || !stackContainsRoller) && !InteractionRoller.NO_RULES) + if (allowFurniture || !stackContainsRoller || InteractionRoller.NO_RULES) { Event furnitureRolledEvent = null; From 9b6a380a3d64130294cdc580e53b24a9c2fa7696 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Thu, 9 May 2019 03:02:41 +0100 Subject: [PATCH 015/118] Fixed magictile placement on non-stackable items when being placed from your inventory. --- .../com/eu/habbo/habbohotel/rooms/Room.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) 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 66afe4f9..5ceafdff 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -5425,23 +5425,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 From 58feeb998c7a65d4f15cb3b3b473a98ef2e354fb Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Fri, 10 May 2019 03:46:32 +0100 Subject: [PATCH 016/118] Fixed Teleports breaking when you pick one up before teleporting is completed. --- .../threading/runnables/teleport/TeleportActionThree.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 fef0aa46..10f8cc5b 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 @@ -39,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()) { @@ -49,7 +52,10 @@ 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; + } RoomTile teleportLocation = targetRoom.getLayout().getTile(targetTeleport.getX(), targetTeleport.getY()); From 7606dcad359b88385e87c8b518cdb9a8d8388345 Mon Sep 17 00:00:00 2001 From: Beny Date: Fri, 10 May 2019 18:45:07 -0400 Subject: [PATCH 017/118] Group forums --- sqlupdates/2_0_0_TO_DEV.sql | 66 +++ .../java/com/eu/habbo/core/CleanerThread.java | 3 +- .../eu/habbo/habbohotel/GameEnvironment.java | 8 - .../habbohotel/catalog/CatalogManager.java | 17 +- .../com/eu/habbo/habbohotel/guilds/Guild.java | 5 +- .../habbo/habbohotel/guilds/GuildManager.java | 3 +- .../habbohotel/guilds/forums/ForumThread.java | 478 ++++++++++++++++++ .../guilds/forums/ForumThreadComment.java | 214 ++++++++ .../guilds/forums/ForumThreadState.java | 33 ++ .../habbohotel/guilds/forums/GuildForum.java | 200 -------- .../guilds/forums/GuildForumComment.java | 157 ------ .../guilds/forums/GuildForumManager.java | 151 ------ .../guilds/forums/GuildForumState.java | 33 -- .../guilds/forums/GuildForumThread.java | 312 ------------ .../com/eu/habbo/habbohotel/users/Habbo.java | 4 +- .../eu/habbo/habbohotel/users/HabboInfo.java | 10 + .../habbo/habbohotel/users/HabboManager.java | 9 +- .../eu/habbo/habbohotel/users/HabboStats.java | 72 +-- .../guilds/forums/GuildForumDataEvent.java | 8 +- .../guilds/forums/GuildForumListEvent.java | 84 ++- .../GuildForumModerateMessageEvent.java | 82 +-- .../forums/GuildForumModerateThreadEvent.java | 37 +- .../forums/GuildForumPostThreadEvent.java | 107 ++-- .../forums/GuildForumThreadUpdateEvent.java | 39 +- .../guilds/forums/GuildForumThreadsEvent.java | 17 +- .../GuildForumThreadsMessagesEvent.java | 38 +- .../forums/GuildForumUpdateSettingsEvent.java | 14 +- .../forums/GuildForumAddCommentComposer.java | 9 +- .../forums/GuildForumCommentsComposer.java | 11 +- .../guilds/forums/GuildForumDataComposer.java | 120 ++++- .../guilds/forums/GuildForumListComposer.java | 60 ++- .../GuildForumThreadMessagesComposer.java | 6 +- .../forums/GuildForumThreadsComposer.java | 45 +- .../forums/PostUpdateMessageComposer.java | 6 +- .../forums/ThreadUpdatedMessageComposer.java | 31 +- .../handshake/ConnectionErrorComposer.java | 35 ++ .../forums/GuildForumThreadBeforeCreated.java | 19 + .../GuildForumThreadCommentBeforeCreated.java | 17 + .../GuildForumThreadCommentCreated.java | 12 + .../forums/GuildForumThreadCreated.java | 12 + 40 files changed, 1450 insertions(+), 1134 deletions(-) create mode 100644 sqlupdates/2_0_0_TO_DEV.sql create mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThread.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadComment.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/ForumThreadState.java delete mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForum.java delete mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumComment.java delete mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumManager.java delete mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumState.java delete mode 100644 src/main/java/com/eu/habbo/habbohotel/guilds/forums/GuildForumThread.java create mode 100644 src/main/java/com/eu/habbo/messages/outgoing/handshake/ConnectionErrorComposer.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadBeforeCreated.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentBeforeCreated.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCommentCreated.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/guilds/forums/GuildForumThreadCreated.java diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql new file mode 100644 index 00000000..c13be708 --- /dev/null +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -0,0 +1,66 @@ +#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/core/CleanerThread.java b/src/main/java/com/eu/habbo/core/CleanerThread.java index 4a72b178..0ac98487 100644 --- a/src/main/java/com/eu/habbo/core/CleanerThread.java +++ b/src/main/java/com/eu/habbo/core/CleanerThread.java @@ -1,6 +1,7 @@ package com.eu.habbo.core; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.forums.ForumThread; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.friends.SearchUserEvent; import com.eu.habbo.messages.incoming.navigator.SearchRoomsEvent; @@ -107,7 +108,7 @@ public class CleanerThread implements Runnable { if (time - LAST_INACTIVE_GUILDS_CLEARED > 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/habbohotel/GameEnvironment.java b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java index af05965b..a9097efe 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(); @@ -116,11 +113,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/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java index 1997b0dc..5cf07b5e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -5,6 +5,7 @@ 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; @@ -1229,18 +1230,12 @@ public class CatalogManager 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(); - } + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); + if(guild != null) { + guild.setForum(true); + guild.needsUpdate = true; + guild.run(); } - } } 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..bb2217f4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/Guild.java @@ -114,7 +114,7 @@ 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); @@ -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; 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/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 019b5abe..9434ad33 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -40,13 +40,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(); 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 9d7efde6..3e1ffba3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -60,6 +60,7 @@ public class HabboInfo implements Runnable private String photoJSON; private int webPublishTimestamp; private String machineID; + public boolean firstVisit = false; public HabboInfo(ResultSet set) { @@ -529,4 +530,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/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index dd783abb..a88f7835 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -119,7 +119,7 @@ public class HabboManager { habbo = new Habbo(set); - if (habbo.firstVisit) + if (habbo.getHabboInfo().firstVisit) { Emulator.getPluginManager().fireEvent(new UserRegisteredEvent(habbo)); } @@ -152,6 +152,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; 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/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/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..c66735fc 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); @@ -68,13 +78,87 @@ public class GuildForumDataComposer extends MessageComposer { this.response.appendInt(guild.canPostThreads().state); this.response.appendInt(guild.canModForum().state); this.response.appendString(errorRead); - this.response.appendString(errorPost); - this.response.appendString(errorStartThread); - this.response.appendString(errorModerate); - this.response.appendString(""); //citizen + this.response.appendString("not_citizen"); //errorPost); + this.response.appendString("not_citizen"); //errorStartThread); + this.response.appendString("not_admin"); //errorModerate); + this.response.appendString("not_citizen"); //citizen 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/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; + } +} From d7965bf476287c3ff2ff929f0158f4561a721d36 Mon Sep 17 00:00:00 2001 From: Beny Date: Fri, 10 May 2019 23:58:55 +0100 Subject: [PATCH 018/118] Added forums_posts_count SQL --- sqlupdates/2_0_0_TO_DEV.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql index c13be708..969d3a8d 100644 --- a/sqlupdates/2_0_0_TO_DEV.sql +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -63,4 +63,6 @@ DROP PROCEDURE IF EXISTS MIGRATION_FORUMS; UPDATE `users_pets` LEFT JOIN `rooms` ON `users_pets`.`room_id` = `rooms`.`id` SET `users_pets`.`room_id` = 0 WHERE `users_pets`.`room_id` != 0 AND `rooms`.`id` IS NULL; +ALTER TABLE `users_settings` ADD COLUMN `forums_post_count` int(11) NULL DEFAULT 0 AFTER `perk_trade`; + #END DATABASE UPDATE: 2.0.0 -> DEV \ No newline at end of file From 34f47b74fd84b88733c7ff0a74ec91ead662bfdd Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 11 May 2019 00:00:56 +0100 Subject: [PATCH 019/118] Fixed permissions on forums --- .../outgoing/guilds/forums/GuildForumDataComposer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 c66735fc..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 @@ -78,10 +78,10 @@ public class GuildForumDataComposer extends MessageComposer { this.response.appendInt(guild.canPostThreads().state); this.response.appendInt(guild.canModForum().state); this.response.appendString(errorRead); - this.response.appendString("not_citizen"); //errorPost); - this.response.appendString("not_citizen"); //errorStartThread); - this.response.appendString("not_admin"); //errorModerate); - this.response.appendString("not_citizen"); //citizen + this.response.appendString(errorPost); + this.response.appendString(errorStartThread); + this.response.appendString(errorModerate); + this.response.appendString(""); //citizen this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId()); //Forum Settings this.response.appendBoolean(guild.getOwnerId() == this.habbo.getHabboInfo().getId() || isStaff); //Can Mod (staff) } From 7a29f56fb814fdb0abf0e8d7f8611652553dfdf3 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 11 May 2019 00:10:07 +0100 Subject: [PATCH 020/118] Added appropriate comments to DiscountComposer. --- .../outgoing/catalog/DiscountComposer.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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..b16c34f1 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 @@ -10,13 +10,18 @@ public class DiscountComposer extends MessageComposer public ServerMessage compose() { this.response.init(Outgoing.DiscountComposer); - this.response.appendInt(100); - this.response.appendInt(6); + + this.response.appendInt(100); // maximum allowed to buy + + this.response.appendInt(6); // free every x + this.response.appendInt(1); this.response.appendInt(1); - this.response.appendInt(2); - this.response.appendInt(40); - this.response.appendInt(99); + + this.response.appendInt(2); // array count for additional extras + this.response.appendInt(40); //extra free at 40 + this.response.appendInt(99); //extra free at 99 + return this.response; } } From f20e4d4c521789fcaf077e5d5d38f173953bcfd8 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 11 May 2019 23:11:20 -0400 Subject: [PATCH 021/118] Resolve "Bug: UpdateUser RCON look attribute" --- .gitlab/issue_templates/Bug.md | 31 + .gitlab/issue_templates/Feature.md | 15 + LICENSE | 674 ++++++++++++++++++ README.md | 1 + .../habbohotel/commands/AboutCommand.java | 2 +- .../interactions/InteractionRoomAds.java | 4 +- .../eu/habbo/messages/rcon/UpdateUser.java | 5 +- 7 files changed, 728 insertions(+), 4 deletions(-) create mode 100644 .gitlab/issue_templates/Bug.md create mode 100644 .gitlab/issue_templates/Feature.md create mode 100644 LICENSE diff --git a/.gitlab/issue_templates/Bug.md b/.gitlab/issue_templates/Bug.md new file mode 100644 index 00000000..c6b2d705 --- /dev/null +++ b/.gitlab/issue_templates/Bug.md @@ -0,0 +1,31 @@ + + + +## Expected Behavior + + +## Current Behavior + + +## Possible Solution + + +## Steps to Reproduce + + +1. +1. +1. +1. + +## Context (Environment) + + + + + +## Detailed Description + + +## Possible Implementation + \ No newline at end of file diff --git a/.gitlab/issue_templates/Feature.md b/.gitlab/issue_templates/Feature.md new file mode 100644 index 00000000..21414ec9 --- /dev/null +++ b/.gitlab/issue_templates/Feature.md @@ -0,0 +1,15 @@ + + + +## Summary + + + +## What is the expected behavior of the new feature? + + +## What is the use case of this feature, is it on Habbo.com? + + +## Other information (e.g. detailed explanation, stacktraces, related issues, suggestions, links for us to have context, eg. stackoverflow, etc) + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..bbe72e8a --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Arcturus Community + Copyright (C) 2019 Morningstar + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Arcturus Community Copyright (C) 2019 Morningstar + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md index 883042c2..cf501d89 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Client build: **PRODUCTION-201611291003-338511768** ## Reporting problems ## You can report problems via the Issue Tracker at https://git.krews.org/morningstar/Arcturus-Community/issues +When making an bug report or a feature request use the template we provide so that it can be categorized correctly and we have more information to replicate a bug or implement a feature correctly. ## Credits ## - TheGeneral diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java index b8ab2b7e..9472cf82 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java @@ -44,7 +44,7 @@ public class AboutCommand extends Command message += "\r" + - "Thanks for using Arcturus. Report issues on the forums. http://arcturus.pw \r\r" + + "Thanks for using Arcturus. Report issues on the forums. http://arcturus.wf \r\r" + " - The General"; gameClient.getHabbo().alert(message); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java index a30a6683..7b92b6dd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java @@ -13,9 +13,9 @@ public class InteractionRoomAds extends InteractionCustomValues public final static THashMap defaultValues = new THashMap() { { - this.put("imageUrl", "http://arcturus.pw/ads_background.png");} + this.put("imageUrl", "");} { - this.put("clickUrl", "http://arcturus.pw");} + this.put("clickUrl", "");} { this.put("offsetX", "0");} { 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..56e08f46 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java @@ -58,7 +58,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()); From 5fd43705d3b3b946a72cf669bdd5ec6aecfa87d4 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 04:51:18 +0100 Subject: [PATCH 022/118] Navigator text search all in one list now --- .../RequestNewNavigatorRoomsEvent.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) 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) From 4deccd7535735a4b055402437bc1d818a7316392 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 05:04:46 +0100 Subject: [PATCH 023/118] Fixed rank badges disappearing --- .../java/com/eu/habbo/habbohotel/commands/BadgeCommand.java | 4 ++-- src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java | 2 +- .../eu/habbo/habbohotel/users/inventory/BadgesComponent.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index a88f7835..64107ea0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -333,7 +333,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/inventory/BadgesComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BadgesComponent.java index a66ee949..16e56a7d 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 @@ -43,7 +43,7 @@ public class BadgesComponent for (Rank rank : Emulator.getGameEnvironment().getPermissionsManager().getRanks(badge.getCode())) { - if (rank.getId() == habbo.getHabboInfo().getId()) + if (rank.getId() == habbo.getHabboInfo().getRank().getId()) { delete = false; break; From 54cf0b1109efabbbb3c4b611a0a08849f0dd0f7b Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 05:12:27 +0100 Subject: [PATCH 024/118] NullPointerException fixed on InteractionGameGate --- .../items/interactions/games/InteractionGameGate.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 e5fc6212..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 @@ -46,7 +46,12 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem } public void updateState(Game game, int maxPlayers) { - int memberCount = game.getTeam(this.teamColor).getMembers().size(); + int memberCount = 0; + + if(game.getTeam(this.teamColor) != null) { + memberCount = game.getTeam(this.teamColor).getMembers().size(); + } + if(memberCount > maxPlayers) { memberCount = maxPlayers; } From d0e12d687117eda855dbf56a5c76870add59c0c1 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 06:12:51 +0100 Subject: [PATCH 025/118] Guild purchase restrictions - Room in use and HC Required --- sqlupdates/2_0_0_TO_DEV.sql | 2 ++ .../incoming/guilds/RequestGuildBuyEvent.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql index 969d3a8d..d68ccbae 100644 --- a/sqlupdates/2_0_0_TO_DEV.sql +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -65,4 +65,6 @@ UPDATE `users_pets` LEFT JOIN `rooms` ON `users_pets`.`room_id` = `rooms`.`id` S ALTER TABLE `users_settings` ADD COLUMN `forums_post_count` int(11) NULL DEFAULT 0 AFTER `perk_trade`; +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('catalog.guild.hc_required', '1'); + #END DATABASE UPDATE: 2.0.0 -> DEV \ No newline at end of file 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..d28961cf 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 @@ -8,6 +8,7 @@ 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 +31,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 +45,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) From 3c4c118d962250d7cae0fe3476c030168b4fb334 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 06:35:08 +0100 Subject: [PATCH 026/118] Fixed guild rights --- .../java/com/eu/habbo/habbohotel/guilds/Guild.java | 12 ++++++------ .../java/com/eu/habbo/habbohotel/rooms/Room.java | 2 +- .../incoming/guilds/GuildChangeSettingsEvent.java | 2 +- .../messages/outgoing/guilds/GuildInfoComposer.java | 2 +- .../outgoing/guilds/GuildManageComposer.java | 6 +++--- .../events/guilds/GuildChangedSettingsEvent.java | 5 ++--- 6 files changed, 14 insertions(+), 15 deletions(-) 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 bb2217f4..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; @@ -119,7 +119,7 @@ public class Guild implements Runnable 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); @@ -200,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/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index 5ceafdff..bc73cbcf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4620,7 +4620,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; } 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/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/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; From 40ab27002b32fd6cebc7fa5cb3a71ec74a1e05fb Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 08:59:01 +0100 Subject: [PATCH 027/118] Fixed a bunch of pathfinder bugs & improved performance --- .../interactions/InteractionTeleport.java | 3 + .../com/eu/habbo/habbohotel/pets/Pet.java | 21 +++ .../com/eu/habbo/habbohotel/rooms/Room.java | 125 +++++++----------- .../eu/habbo/habbohotel/rooms/RoomLayout.java | 26 ++-- .../habbo/habbohotel/rooms/RoomManager.java | 8 +- .../eu/habbo/habbohotel/rooms/RoomTile.java | 21 ++- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 81 +++++++----- .../incoming/rooms/RequestRoomLoadEvent.java | 7 +- .../rooms/pets/CompostMonsterplantEvent.java | 7 +- .../incoming/rooms/pets/PetPickupEvent.java | 7 +- .../teleport/TeleportActionFive.java | 2 - .../teleport/TeleportActionThree.java | 2 +- 12 files changed, 155 insertions(+), 155 deletions(-) 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 1dd5e11e..7f83c904 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 @@ -102,6 +102,7 @@ public class InteractionTeleport extends HabboItem walkable = this.getBaseItem().allowWalk(); room.updateTile(currentLocation); tryTeleport(client, room); + unit.removeOverrideTile(currentLocation); }); onFail.add(() -> { @@ -110,10 +111,12 @@ public class InteractionTeleport extends HabboItem this.setExtradata("0"); room.updateItem(this); this.roomUnitID = -1; + unit.removeOverrideTile(currentLocation); }); walkable = true; room.updateTile(currentLocation); + unit.addOverrideTile(currentLocation); unit.setGoalLocation(currentLocation); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); } 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/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index bc73cbcf..2fe6d52b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -701,59 +701,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) @@ -849,7 +807,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()) @@ -899,11 +857,11 @@ public class Room implements Comparable, ISerialize, Runnable } else { - habbo.getRoomUnit().setZ(item.getZ() + item.getBaseItem().getHeight()); + habbo.getRoomUnit().setZ(item.getZ() + Item.getCurrentHeight(item)); if (item.getBaseItem().allowLay()) { - habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + item.getBaseItem().getHeight()) + ""); + habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + Item.getCurrentHeight(item)) + ""); } } } @@ -938,10 +896,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()); } @@ -1596,7 +1553,7 @@ public class Room implements Comparable, ISerialize, Runnable for(HabboItem item : getItemsAt(rollerTile)) { - if(item.getZ() >= roller.getZ() + roller.getBaseItem().getHeight()) { + if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { itemsOnRoller.add(item); } } @@ -1689,7 +1646,7 @@ public class Room implements Comparable, ISerialize, Runnable } else { - zOffset = -roller.getBaseItem().getHeight() + tileInFront.getStackHeight() - rollerTile.z; + zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.z; } if (allowUsers) @@ -1917,7 +1874,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()) { @@ -1932,15 +1889,8 @@ 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.setRotation(RoomUserRotation.values()[topItem.getRotation()]); unit.sitUpdate = false; @@ -1966,14 +1916,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) @@ -2392,9 +2335,8 @@ public class Room implements Comparable, ISerialize, Runnable for (Pet pet : this.currentPets.valueCollection()) { try { if (pet.getUserId() != excludeUserId) { - pet.setRoom(null); - removedPets.add(pet); - this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); + + pet.removeFromRoom(); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); if (habbo != null) { @@ -3194,8 +3136,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) @@ -3408,6 +3362,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); @@ -3570,7 +3528,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) @@ -3580,7 +3538,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) @@ -4208,7 +4166,8 @@ public class Room implements Comparable, ISerialize, Runnable { item = habboItem; } - } else + } + else { if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) { @@ -4240,7 +4199,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); } @@ -4319,6 +4278,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) { + canStack = true; + height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair); + } } } 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 7bd8f853..1bcbdf0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -262,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,20 +274,6 @@ public class RoomLayout openList.add(oldTile.copy()); - List unitsAt = new ArrayList<>(); - - for(Bot b : this.room.getCurrentBots().valueCollection()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - - for(Habbo b : this.room.getCurrentHabbos().values()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - - for(Pet b : this.room.getCurrentPets().valueCollection()) { - unitsAt.add(b.getRoomUnit().getCurrentLocation()); - } - long startMillis = System.currentTimeMillis(); while (true) { @@ -310,6 +296,14 @@ 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.equals(goalLocation) && (currentAdj.state == RoomTileState.BLOCKED || currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY)) { @@ -329,7 +323,7 @@ public class RoomLayout if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; //Check if the tile has habbos. - if (unitsAt.contains(currentAdj) && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) + if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { closedList.add(currentAdj); openList.remove(currentAdj); 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 bb77a5e1..06cbd713 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -750,7 +750,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); } @@ -824,7 +825,6 @@ public class RoomManager if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting) { - RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); if (doorTile != null) @@ -836,6 +836,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(); @@ -1100,9 +1101,8 @@ public class RoomManager habbo.getRoomUnit().setPathFinderRoom(null); this.logExit(habbo); - room.removeHabbo(habbo); + room.removeHabbo(habbo, true); - room.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose()); if (redirectToHotelView) { habbo.getClient().sendResponse(new HotelViewComposer()); 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..356af4ff 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,7 @@ package com.eu.habbo.habbohotel.rooms; +import gnu.trove.set.hash.THashSet; + public class RoomTile { public final short x; @@ -10,12 +12,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 THashSet units; + public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack) { @@ -25,6 +28,7 @@ public class RoomTile this.stackHeight = z; this.state = state; this.setAllowStack(allowStack); + this.units = new THashSet<>(); } public RoomTile(RoomTile tile) @@ -43,6 +47,7 @@ public class RoomTile { this.allowStack = false; } + this.units = tile.units; } public double getStackHeight() @@ -199,4 +204,18 @@ public class RoomTile { return this.x == x && this.y == y; } + + public void addUnit(RoomUnit unit) { + if(!this.units.contains(unit)) { + this.units.add(unit); + } + } + + public void removeUnit(RoomUnit unit) { + this.units.remove(unit); + } + + public boolean hasUnits() { + return this.units.size() > 0; + } } \ 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 161284a1..597afdab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -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; @@ -72,6 +74,7 @@ public class RoomUnit private int idleTimer; private Room room; private RoomRightLevels rightsLevel = RoomRightLevels.NONE; + private THashSet overridableTiles; public RoomUnit() { @@ -87,6 +90,7 @@ public class RoomUnit this.walkTimeOut = Emulator.getIntUnixTimestamp(); this.effectId = 0; this.isKicked = false; + this.overridableTiles = new THashSet<>(); } public void clearWalking() @@ -113,11 +117,6 @@ public class RoomUnit { try { - if (this.isTeleporting) - { - return false; - } - Habbo rider = null; if(this.getRoomUnitType() == RoomUnitType.PET) { Pet pet = room.getPet(this); @@ -179,25 +178,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) { 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(); @@ -214,6 +208,13 @@ public class RoomUnit } } + if (canfastwalk && this.fastWalk) + { + if(this.path.size() > 1) { + next = this.path.poll(); + } + } + if (next == null) return true; @@ -252,7 +253,7 @@ public class RoomUnit //if(!(this.path.size() == 0 && canSitNextTile)) { - if (!room.tileWalkable(next.x, next.y)) + if (!room.tileWalkable(next.x, next.y) && !overrideChecks) { this.room = room; this.findPath(); @@ -281,7 +282,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) { @@ -343,20 +344,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 @@ -574,8 +562,8 @@ public class RoomUnit if (location != null) { this.startLocation = location; - this.previousLocation = location; - this.currentLocation = location; + setPreviousLocation(location); + setCurrentLocation(location); this.goalLocation = location; } } @@ -584,7 +572,11 @@ public class RoomUnit { if (location != null) { - this.currentLocation = location; + if(this.currentLocation != null) { + this.currentLocation.removeUnit(this); + } + this.currentLocation = location; + location.addUnit(this); } } @@ -616,9 +608,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); } } @@ -811,4 +803,25 @@ public class RoomUnit 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(); + } } 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/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/PetPickupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetPickupEvent.java index 19f5a6ed..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 @@ -44,12 +44,7 @@ public class PetPickupEvent extends MessageHandler } } - room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); - room.removePet(petId); - pet.setRoomUnit(null); - pet.setRoom(null); - pet.needsUpdate = true; - + pet.removeFromRoom(); Emulator.getThreading().run(pet); if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) 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 fe8d268f..be318de4 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 @@ -35,8 +35,6 @@ class TeleportActionFive implements Runnable if (tile != null) { - this.client.getHabbo().getRoomUnit().setPreviousLocation(currentLocation); - this.client.getHabbo().getRoomUnit().setPreviousLocationZ(currentLocation.getStackHeight()); this.client.getHabbo().getRoomUnit().setGoalLocation(tile); this.client.getHabbo().getRoomUnit().statusUpdate(true); } 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 10f8cc5b..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 @@ -68,7 +68,7 @@ class TeleportActionThree implements Runnable if(targetRoom != this.room) { - this.room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); + this.room.removeHabbo(this.client.getHabbo(), true); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); } From e225d4d7b4738ea70ac6fa8cbe33242ffb912ffa Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 09:15:24 +0100 Subject: [PATCH 028/118] Added new config - catalog.ltd.random --- sqlupdates/2_0_0_TO_DEV.sql | 1 + .../catalog/CatalogLimitedConfiguration.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql index d68ccbae..858776c5 100644 --- a/sqlupdates/2_0_0_TO_DEV.sql +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -66,5 +66,6 @@ UPDATE `users_pets` LEFT JOIN `rooms` ON `users_pets`.`room_id` = `rooms`.`id` S ALTER TABLE `users_settings` ADD COLUMN `forums_post_count` int(11) NULL DEFAULT 0 AFTER `perk_trade`; INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('catalog.guild.hc_required', '1'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('catalog.ltd.random', '1'); #END DATABASE UPDATE: 2.0.0 -> DEV \ No newline at end of file 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); + } } } From 1fe340f39b8138b735cc5695ad8f19c5b8f68258 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 11:26:40 +0100 Subject: [PATCH 029/118] One way gates perfected --- .../interactions/InteractionOneWayGate.java | 61 ++++++++++++++++--- 1 file changed, 51 insertions(+), 10 deletions(-) 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..eee7d780 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(() -> { + walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentLocation); + room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose()); + unit.removeOverrideTile(currentLocation); + + unit.setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4)); + }); + + onFail.add(() -> { + 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) { From 373fb4b3618d555cff7c5921851025b085b356fa Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.ngh.codes> Date: Sun, 12 May 2019 06:35:23 -0400 Subject: [PATCH 030/118] Add Battle Banzai tile filling --- .../games/battlebanzai/BattleBanzaiGame.java | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) 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 f61002ff..3fbb2a99 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 @@ -21,8 +21,7 @@ import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; -import java.util.Collection; -import java.util.Map; +import java.util.*; public class BattleBanzaiGame extends Game { @@ -269,6 +268,11 @@ public class BattleBanzaiGame extends Game 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) { @@ -284,8 +288,85 @@ public class BattleBanzaiGame extends Game { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked")); } + + if (doNotCheckFill) return; + + int x = item.getX(); + int y = item.getY(); + + List> filledAreas = new ArrayList<>(); + filledAreas.add(this.floodFill(x, y - 1, this.lockedTiles.get(teamColor), new ArrayList<>())); + filledAreas.add(this.floodFill(x, y + 1, this.lockedTiles.get(teamColor), new ArrayList<>())); + filledAreas.add(this.floodFill(x - 1, y, this.lockedTiles.get(teamColor), new ArrayList<>())); + filledAreas.add(this.floodFill(x + 1, y, this.lockedTiles.get(teamColor), new ArrayList<>())); + + 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) + { + if (this.isOutOfBounds(x, y)) 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)); + result.add(this.floodFill(x, y + 1, lockedTiles, stack)); + result.add(this.floodFill(x - 1, y, lockedTiles, stack)); + result.add(this.floodFill(x + 1, y, lockedTiles, stack)); + + 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; + } public void refreshCounters() { From c05bd018359e55c7cac6b6e227a5ddd4cf18318b Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 11:48:56 +0100 Subject: [PATCH 031/118] InteractionInformationTerminal implemented correctly --- .../InteractionInformationTerminal.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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"))); + } } } From c09f199e0b51d2b6b960edd9213d4a6cbf98bb67 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 11:50:40 +0100 Subject: [PATCH 032/118] Remove unnecessary log --- .../items/interactions/games/InteractionGameTimer.java | 1 - 1 file changed, 1 deletion(-) 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 81e6df9d..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 @@ -291,7 +291,6 @@ public abstract class InteractionGameTimer extends HabboItem implements Runnable if (game == null) { try { - System.out.println(gameClass.getName()); game = gameClass.getDeclaredConstructor(Room.class).newInstance(room); room.addGame(game); } catch (Exception e) { From 2071bc78c35feba68709c5154ee6aae4b6ae11b4 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 12 May 2019 10:41:57 -0400 Subject: [PATCH 033/118] Make bots rotate on furniture rotation --- .../com/eu/habbo/habbohotel/rooms/Room.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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 2fe6d52b..6865ec8c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -759,6 +759,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) @@ -879,6 +880,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<>(); @@ -5449,6 +5485,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); @@ -5572,6 +5609,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; } @@ -5620,6 +5658,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; } From 5c3ce204ef635ed5128670065210927408933229 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 12 May 2019 11:03:40 -0400 Subject: [PATCH 034/118] Make bots roll on rollers and clean up code --- .../com/eu/habbo/habbohotel/rooms/Room.java | 492 +++++++++--------- 1 file changed, 257 insertions(+), 235 deletions(-) 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 6865ec8c..3e55ed05 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1570,244 +1570,266 @@ 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; + + THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); + THashSet botsOnRoller = Room.this.getBotsAt(Room.this.layout.getTile(roller.getX(), roller.getY())); + THashSet itemsOnRoller = new THashSet<>(); + + RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); + itemsOnRoller.addAll(this.getItemsAt(rollerTile)); + itemsOnRoller.remove(roller); + + if (habbosOnRoller.isEmpty() && itemsOnRoller.isEmpty() && botsOnRoller.isEmpty()) { - //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); - - if (habbosOnRoller.isEmpty()) - { - if (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 (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) - return true; - - THashSet itemsNewTile = new THashSet<>(); - - for(HabboItem item : getItemsAt(tileInFront)) - { - itemsNewTile.add(item); - } - - itemsNewTile.removeAll(itemsOnRoller); - List toRemove = new ArrayList<>(); - for (HabboItem item : itemsOnRoller) - { - 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); - - 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"))) - { - 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; - } - } - - 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); - } - - 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; } + + 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 (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) + 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())) + { + toRemove.add(item); + } + } + itemsOnRoller.removeAll(toRemove); + HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y); + + 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"))) + { + 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; + } + } + + 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); + } + + 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; + } + + for (Bot bot: botsOnRoller) + { + if (rolledUnitIds.contains(bot.getRoomUnit().getId())) continue; + + rolledUnitIds.add(bot.getRoomUnit().getId()); + + if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) + continue; + + if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + { + RoomTile tile = tileInFront.copy(); + tile.setStackHeight(bot.getRoomUnit().getZ() + zOffset); + + updatedUnit.remove(bot.getRoomUnit()); + messages.add(new RoomUnitOnRollerComposer(bot.getRoomUnit(), roller, bot.getRoomUnit().getCurrentLocation(), bot.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(bot.getRoomUnit(), room, null); + } catch (Exception e) + { + Emulator.getLogging().logErrorLine(e); + } + } + } + } + + if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) + bot.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; }); From cdd31e87a43df3403577ef96b571ad84f90ea71c Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Sun, 12 May 2019 18:33:16 +0100 Subject: [PATCH 035/118] Started RC-2. --- src/main/java/com/eu/habbo/Emulator.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index d185e644..bbea6568 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -39,7 +39,10 @@ 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-2"; + + + public static final String version = "Arcturus Morningstar"+ " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW; public static MessengerBuddy publicChatBuddy; @@ -159,9 +162,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); @@ -457,12 +460,12 @@ public final class Emulator private static final String logo = - " \n" + - " __ ___ _ ARCTURUS __ \n" + + " \n" + + " __ ___ _ A R C T U R U S __ \n" + " / |/ /___ _________ (_)___ ____ ______/ /_____ ______ \n" + " / /|_/ / __ \\/ ___/ __ \\/ / __ \\/ __ `/ ___/ __/ __ `/ ___/ \n" + " / / / / /_/ / / / / / / / / / / /_/ (__ ) /_/ /_/ / / \n" + "/_/ /_/\\____/_/ /_/ /_/_/_/ /_/\\__, /____/\\__/\\__,_/_/ \n" + - " /____/ Love You Wesley x \n" + - " \n" ; + " /____/ \n" + + " \n" ; } \ No newline at end of file From 1c42bb9a5954712b04515dabd8dd4beb915cd571 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 12 May 2019 14:45:50 -0400 Subject: [PATCH 036/118] Fix beds on rotate --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 3e55ed05..6a850015 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -850,7 +850,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()); @@ -859,11 +859,6 @@ public class Room implements Comparable, ISerialize, Runnable else { habbo.getRoomUnit().setZ(item.getZ() + Item.getCurrentHeight(item)); - - if (item.getBaseItem().allowLay()) - { - habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + Item.getCurrentHeight(item)) + ""); - } } } else From a8f6a641d8a4285ee04b05ad6ea47ce1045ba554 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 19:54:39 +0100 Subject: [PATCH 037/118] Fixed banzai points --- sqlupdates/2_0_0_TO_DEV.sql | 3 +++ .../habbohotel/games/battlebanzai/BattleBanzaiGame.java | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sqlupdates/2_0_0_TO_DEV.sql b/sqlupdates/2_0_0_TO_DEV.sql index 858776c5..363a6993 100644 --- a/sqlupdates/2_0_0_TO_DEV.sql +++ b/sqlupdates/2_0_0_TO_DEV.sql @@ -67,5 +67,8 @@ ALTER TABLE `users_settings` ADD COLUMN `forums_post_count` int(11) NULL DEFAULT INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('catalog.guild.hc_required', '1'); INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('catalog.ltd.random', '1'); +UPDATE `emulator_settings` SET `value` = '0' WHERE `key` = 'hotel.banzai.points.tile.steal'; +UPDATE `emulator_settings` SET `value` = '0' WHERE `key` = 'hotel.banzai.points.tile.fill'; +UPDATE `emulator_settings` SET `value` = '1' WHERE `key` = 'hotel.banzai.points.tile.lock'; #END DATABASE UPDATE: 2.0.0 -> DEV \ No newline at end of file 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 3fbb2a99..f4bafa2d 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 @@ -29,13 +29,13 @@ 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 tileCount; From 2b19bdd0d6f32304669a77259c14447d20854437 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 21:31:59 +0100 Subject: [PATCH 038/118] Build hash in console --- src/main/java/com/eu/habbo/Emulator.java | 50 ++++++++++++++++++++---- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index bbea6568..16f54584 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -21,11 +21,15 @@ 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.Random; +import java.util.zip.Checksum; public final class Emulator { @@ -41,22 +45,19 @@ public final class Emulator public final static String PREVIEW = "RC-2"; - public static final String version = "Arcturus Morningstar"+ " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW; + public static String build = ""; + public static MessengerBuddy publicChatBuddy; - 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; @@ -92,10 +93,12 @@ public final class Emulator { try { + 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(); @@ -196,6 +199,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 Date: Sun, 12 May 2019 22:54:26 +0100 Subject: [PATCH 039/118] Plugins can now create friend list entries - See Arcturus Extended for examples --- src/main/java/com/eu/habbo/Emulator.java | 4 -- .../habbo/habbohotel/messenger/Messenger.java | 5 +++ .../habbohotel/messenger/MessengerBuddy.java | 41 ++++++++++++++++++- .../friends/FriendPrivateMessageEvent.java | 28 +------------ .../outgoing/friends/FriendsComposer.java | 7 ++-- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index 16f54584..6884bb63 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -49,9 +49,6 @@ public final class Emulator public static String build = ""; - - public static MessengerBuddy publicChatBuddy; - public static boolean isReady = false; public static boolean isShuttingDown = false; @@ -100,7 +97,6 @@ public final class Emulator 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(); 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/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/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) From 8b3364c7f30e5c963fbde367452f2105217a0e71 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 13 May 2019 00:04:02 +0100 Subject: [PATCH 040/118] Ability to override ids on FriendChatMessageComposer --- .../friends/FriendChatMessageComposer.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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; From db345025e7a8e877f790378f2906d61718f39ffe Mon Sep 17 00:00:00 2001 From: Harmonic Date: Sun, 12 May 2019 21:36:53 -0400 Subject: [PATCH 041/118] Revert "Merge branch 'bot-rollers' into 'dev'" This reverts merge request !25 --- .../com/eu/habbo/habbohotel/rooms/Room.java | 424 +++++++++--------- 1 file changed, 201 insertions(+), 223 deletions(-) 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 6a850015..970fb501 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1565,266 +1565,244 @@ public class Room implements Comparable, ISerialize, Runnable List rollerFurniIds = new ArrayList<>(); List rolledUnitIds = new ArrayList<>(); - - this.roomSpecialTypes.getRollers().forEachValue(roller -> { - - HabboItem newRoller = null; - - THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); - THashSet botsOnRoller = Room.this.getBotsAt(Room.this.layout.getTile(roller.getX(), roller.getY())); - THashSet itemsOnRoller = new THashSet<>(); - - RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); - itemsOnRoller.addAll(this.getItemsAt(rollerTile)); - itemsOnRoller.remove(roller); - - if (habbosOnRoller.isEmpty() && itemsOnRoller.isEmpty() && botsOnRoller.isEmpty()) + this.roomSpecialTypes.getRollers().forEachValue(new TObjectProcedure() + { + @Override + public boolean execute(InteractionRoller roller) { - return true; - } - - RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation()); - - if (tileInFront == null) - return true; + //if(Double.compare(roller.getZ(), this.layout.getHeightAtSquare(roller.getX(), roller.getY())) != 0) - if (!Room.this.layout.tileExists(tileInFront.x, tileInFront.y)) - return true; + //} - if (tileInFront.state == RoomTileState.INVALID) - return true; + HabboItem newRoller = null; - if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY)) - return true; + THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); + THashSet itemsOnRoller = new THashSet<>(); - if (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) - return true; + RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); - 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())) + for(HabboItem item : getItemsAt(rollerTile)) { - toRemove.add(item); + if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { + itemsOnRoller.add(item); + } } - } - itemsOnRoller.removeAll(toRemove); - HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y); - boolean allowUsers = true; - boolean allowFurniture = true; - boolean stackContainsRoller = false; + itemsOnRoller.remove(roller); - for (HabboItem item : itemsNewTile) - { - if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1"))) + if (habbosOnRoller.isEmpty()) { - allowUsers = false; + if (itemsOnRoller.isEmpty()) + return true; } - if (item instanceof InteractionRoller) - { - newRoller = item; - stackContainsRoller = true; - if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) + 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 (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) + return true; + + THashSet itemsNewTile = new THashSet<>(); + + for(HabboItem item : getItemsAt(tileInFront)) + { + itemsNewTile.add(item); + } + + itemsNewTile.removeAll(itemsOnRoller); + List toRemove = new ArrayList<>(); + for (HabboItem item : itemsOnRoller) + { + 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); + + 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"))) { 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) + { + 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); } - break; - } else - { - allowFurniture = false; - } - } - - 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); - } - - 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)) + for (Habbo habbo : habbosOnRoller) { - RoomTile tile = tileInFront.copy(); - tile.setStackHeight(habbo.getRoomUnit().getZ() + zOffset); - if (roomUserRolledEvent != null) - { - roomUserRolledEvent = new UserRolledEvent(habbo, roller, tile); - Emulator.getPluginManager().fireEvent(roomUserRolledEvent); + if (rolledUnitIds.contains(habbo.getRoomUnit().getId())) continue; - if (roomUserRolledEvent.isCancelled()) - 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); + } + } + } } - updatedUnit.remove(habbo.getRoomUnit()); - messages.add(new RoomUnitOnRollerComposer(habbo.getRoomUnit(), roller, habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getZ(), tile, tile.getStackHeight(), room)); + if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) + habbo.getRoomUnit().sitUpdate = true; - if (itemsOnRoller.isEmpty()) + 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() { - HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); - - if (item != null && itemsNewTile.contains(item)) + @Override + public int compare(HabboItem o1, HabboItem o2) { - try + 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) { - item.onWalkOn(habbo.getRoomUnit(), room, null); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); + 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 (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) - habbo.getRoomUnit().sitUpdate = true; - - break; } - - for (Bot bot: botsOnRoller) + + + if (!messages.isEmpty()) { - if (rolledUnitIds.contains(bot.getRoomUnit().getId())) continue; - - rolledUnitIds.add(bot.getRoomUnit().getId()); - - if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) - continue; - - if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + for (MessageComposer message : messages) { - RoomTile tile = tileInFront.copy(); - tile.setStackHeight(bot.getRoomUnit().getZ() + zOffset); - - updatedUnit.remove(bot.getRoomUnit()); - messages.add(new RoomUnitOnRollerComposer(bot.getRoomUnit(), roller, bot.getRoomUnit().getCurrentLocation(), bot.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(bot.getRoomUnit(), room, null); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - } - } - } + room.sendComposer(message.compose()); } - - if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) - bot.getRoomUnit().sitUpdate = true; - - break; + messages.clear(); } + + return 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; }); From a6c3626a9660b11fdcb936ebbad6dc1ea72bc6dc Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 12 May 2019 22:09:16 -0400 Subject: [PATCH 042/118] Revert "Revert "Merge branch 'bot-rollers' into 'dev'"" This reverts commit db345025e7a8e877f790378f2906d61718f39ffe --- .../com/eu/habbo/habbohotel/rooms/Room.java | 492 +++++++++--------- 1 file changed, 257 insertions(+), 235 deletions(-) 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 970fb501..6a850015 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1565,244 +1565,266 @@ 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; + + THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); + THashSet botsOnRoller = Room.this.getBotsAt(Room.this.layout.getTile(roller.getX(), roller.getY())); + THashSet itemsOnRoller = new THashSet<>(); + + RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); + itemsOnRoller.addAll(this.getItemsAt(rollerTile)); + itemsOnRoller.remove(roller); + + if (habbosOnRoller.isEmpty() && itemsOnRoller.isEmpty() && botsOnRoller.isEmpty()) { - //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); - - if (habbosOnRoller.isEmpty()) - { - if (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 (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) - return true; - - THashSet itemsNewTile = new THashSet<>(); - - for(HabboItem item : getItemsAt(tileInFront)) - { - itemsNewTile.add(item); - } - - itemsNewTile.removeAll(itemsOnRoller); - List toRemove = new ArrayList<>(); - for (HabboItem item : itemsOnRoller) - { - 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); - - 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"))) - { - 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; - } - } - - 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); - } - - 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; } + + 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 (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) + 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())) + { + toRemove.add(item); + } + } + itemsOnRoller.removeAll(toRemove); + HabboItem topItem = Room.this.getTopItemAt(tileInFront.x, tileInFront.y); + + 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"))) + { + 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; + } + } + + 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); + } + + 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; + } + + for (Bot bot: botsOnRoller) + { + if (rolledUnitIds.contains(bot.getRoomUnit().getId())) continue; + + rolledUnitIds.add(bot.getRoomUnit().getId()); + + if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) + continue; + + if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + { + RoomTile tile = tileInFront.copy(); + tile.setStackHeight(bot.getRoomUnit().getZ() + zOffset); + + updatedUnit.remove(bot.getRoomUnit()); + messages.add(new RoomUnitOnRollerComposer(bot.getRoomUnit(), roller, bot.getRoomUnit().getCurrentLocation(), bot.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(bot.getRoomUnit(), room, null); + } catch (Exception e) + { + Emulator.getLogging().logErrorLine(e); + } + } + } + } + + if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) + bot.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; }); From 2300c006fd2476dcba868e015b8c5970f8702eea Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 13 May 2019 03:14:34 +0100 Subject: [PATCH 043/118] Fixed chairs going up when rotated --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6a850015..02ae5d28 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4333,7 +4333,7 @@ public class Room implements Comparable, ISerialize, Runnable } HabboItem lowestChair = this.getLowestChair(x, y); - if(lowestChair != null) { + if(lowestChair != null && lowestChair != exclude) { canStack = true; height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair); } From 3cbb9f5bd84b8941054da9fb7ada460ea8c4f5af Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Mon, 13 May 2019 03:31:21 +0100 Subject: [PATCH 044/118] Roller fixes. --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 02ae5d28..b1c6f86d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1575,7 +1575,14 @@ public class Room implements Comparable, ISerialize, Runnable THashSet itemsOnRoller = new THashSet<>(); RoomTile rollerTile = Room.this.layout.getTile(roller.getX(), roller.getY()); - itemsOnRoller.addAll(this.getItemsAt(rollerTile)); + for(HabboItem item : getItemsAt(rollerTile)) + { + if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { + itemsOnRoller.add(item); + } + } + + // itemsOnRoller.addAll(this.getItemsAt(rollerTile)); itemsOnRoller.remove(roller); if (habbosOnRoller.isEmpty() && itemsOnRoller.isEmpty() && botsOnRoller.isEmpty()) From 0c21424c5a1f234e8ba36a59d71b312b72782035 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 13 May 2019 04:11:27 +0100 Subject: [PATCH 045/118] Fix bots, pets and users on rollers --- .../com/eu/habbo/habbohotel/rooms/Room.java | 137 ++++++++---------- .../eu/habbo/habbohotel/rooms/RoomTile.java | 8 + .../rooms/users/RoomUnitOnRollerComposer.java | 8 - 3 files changed, 69 insertions(+), 84 deletions(-) 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 b1c6f86d..da90908c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -24,6 +24,7 @@ import com.eu.habbo.habbohotel.messenger.MessengerBuddy; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetManager; +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; @@ -52,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; @@ -1570,11 +1572,13 @@ public class Room implements Comparable, ISerialize, Runnable HabboItem newRoller = null; - THashSet habbosOnRoller = Room.this.getHabbosAt(roller.getX(), roller.getY()); - THashSet botsOnRoller = Room.this.getBotsAt(Room.this.layout.getTile(roller.getX(), roller.getY())); + RoomTile rollerTile = this.getLayout().getTile(roller.getX(), roller.getY()); + + if(rollerTile == null) + return true; + 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)) { @@ -1585,17 +1589,14 @@ public class Room implements Comparable, ISerialize, Runnable // itemsOnRoller.addAll(this.getItemsAt(rollerTile)); itemsOnRoller.remove(roller); - if (habbosOnRoller.isEmpty() && itemsOnRoller.isEmpty() && botsOnRoller.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; @@ -1605,7 +1606,7 @@ public class Room implements Comparable, ISerialize, Runnable if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.state == RoomTileState.SIT || tileInFront.state == RoomTileState.LAY)) return true; - if (Room.this.hasHabbosAt(tileInFront.x, tileInFront.y)) + if (tileInFront.hasUnits()) return true; THashSet itemsNewTile = new THashSet<>(); @@ -1679,92 +1680,76 @@ public class Room implements Comparable, ISerialize, Runnable roomUserRolledEvent = new UserRolledEvent(null, null, null); } - for (Habbo habbo : habbosOnRoller) - { - if (rolledUnitIds.contains(habbo.getRoomUnit().getId())) continue; + ArrayList unitsOnTile = new ArrayList(rollerTile.getUnits()); - 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); - } - } + 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); } } - - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) - habbo.getRoomUnit().sitUpdate = true; - - break; } - - for (Bot bot: botsOnRoller) - { - if (rolledUnitIds.contains(bot.getRoomUnit().getId())) continue; - rolledUnitIds.add(bot.getRoomUnit().getId()); + for(RoomUnit unit : unitsOnTile) { + if (rolledUnitIds.contains(unit.getId())) continue; if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) continue; - if (!bot.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + if(unit.hasStatus(RoomUnitStatus.MOVE)) + continue; + + RoomTile tile = tileInFront.copy(); + tile.setStackHeight(unit.getZ() + zOffset); + + if (roomUserRolledEvent != null && unit.getRoomUnitType() == RoomUnitType.USER) { - RoomTile tile = tileInFront.copy(); - tile.setStackHeight(bot.getRoomUnit().getZ() + zOffset); + roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tile); + Emulator.getPluginManager().fireEvent(roomUserRolledEvent); - updatedUnit.remove(bot.getRoomUnit()); - messages.add(new RoomUnitOnRollerComposer(bot.getRoomUnit(), roller, bot.getRoomUnit().getCurrentLocation(), bot.getRoomUnit().getZ(), tile, tile.getStackHeight(), room)); + if (roomUserRolledEvent.isCancelled()) + continue; + } - if (itemsOnRoller.isEmpty()) + // horse riding + boolean isRiding = false; + if(unit.getRoomUnitType() == RoomUnitType.USER) { + Habbo rollingHabbo = this.getHabbo(unit); + 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(), 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), room)); + + if (itemsOnRoller.isEmpty()) + { + HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); + + if (item != null && itemsNewTile.contains(item)) { - HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); - - if (item != null && itemsNewTile.contains(item)) + try { - try - { - item.onWalkOn(bot.getRoomUnit(), room, null); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - } + item.onWalkOn(unit, room, null); + } catch (Exception e) + { + Emulator.getLogging().logErrorLine(e); } } } - if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) - bot.getRoomUnit().sitUpdate = true; - - break; + if(unit.hasStatus(RoomUnitStatus.SIT)) { + unit.sitUpdate = true; + } } } 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 356af4ff..6b0f4918 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -2,6 +2,10 @@ package com.eu.habbo.habbohotel.rooms; import gnu.trove.set.hash.THashSet; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + public class RoomTile { public final short x; @@ -205,6 +209,10 @@ public class RoomTile return this.x == x && this.y == y; } + public List getUnits() { + return new ArrayList(this.units); + } + public void addUnit(RoomUnit unit) { if(!this.units.contains(unit)) { this.units.add(unit); 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..42c1b93b 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 @@ -46,14 +46,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); From af92316188abecc186b6fdb9400f491181671238 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 13 May 2019 04:18:12 +0100 Subject: [PATCH 046/118] Removed whitespace --- .../rooms/users/RoomUnitOnRollerComposer.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) 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 42c1b93b..70b79890 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 @@ -62,19 +62,13 @@ 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; - } - - //}); + 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; + } } else { From 419c3d07af27ff38902cb3500d99c89639e2515c Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 13 May 2019 05:14:29 +0100 Subject: [PATCH 047/118] Fixed wired toggle timers not working with user triggers --- .../wired/effects/WiredEffectToggleFurni.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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..5da0bd05 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,7 @@ 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()}); + item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{item.getExtradata().length() == 0 ? 0 : Integer.valueOf(item.getExtradata()), this.getType()}); } } catch (Exception e) From 0e56cba7a1555eb820452bd1098b1c76a719834c Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Mon, 13 May 2019 13:56:47 -0400 Subject: [PATCH 048/118] Fix number formatting error in toggle furni effect --- .../wired/effects/WiredEffectToggleFurni.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 5da0bd05..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 @@ -146,7 +146,15 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) { - item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? 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) From 23ae60119b08de083be14033ec6d4da1764e0ef9 Mon Sep 17 00:00:00 2001 From: Beny Date: Tue, 14 May 2019 18:47:57 +0100 Subject: [PATCH 049/118] Potential issue in RoomTile removeUnit fixed. --- .../eu/habbo/habbohotel/rooms/RoomTile.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 6b0f4918..c284d37a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -2,7 +2,6 @@ package com.eu.habbo.habbohotel.rooms; import gnu.trove.set.hash.THashSet; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; @@ -21,7 +20,7 @@ public class RoomTile private short gCosts; private short hCosts; - private THashSet units; + private final THashSet units; public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack) @@ -210,20 +209,28 @@ public class RoomTile } public List getUnits() { - return new ArrayList(this.units); + synchronized (this.units) { + return new ArrayList(this.units); + } } public void addUnit(RoomUnit unit) { - if(!this.units.contains(unit)) { - this.units.add(unit); + synchronized (this.units) { + if (!this.units.contains(unit)) { + this.units.add(unit); + } } } public void removeUnit(RoomUnit unit) { - this.units.remove(unit); + synchronized (this.units) { + this.units.remove(unit); + } } public boolean hasUnits() { - return this.units.size() > 0; + synchronized (this.units) { + return this.units.size() > 0; + } } } \ No newline at end of file From 3b480db9f6ec3ef71a5d8461d617e1999fd39fce Mon Sep 17 00:00:00 2001 From: Harmony Date: Tue, 14 May 2019 20:14:15 +0100 Subject: [PATCH 050/118] Make plugins window style configurable between default and the old scrollable style --- sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql | 5 +++++ .../habbo/habbohotel/commands/PluginsCommand.java | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql diff --git a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql new file mode 100644 index 00000000..568aeff0 --- /dev/null +++ b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql @@ -0,0 +1,5 @@ +#DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 + +INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('commands.plugins.oldstyle', '0'); + +#END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file 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; } From b67fa1b27b55fc8e776cae2fca4dd3085fc07503 Mon Sep 17 00:00:00 2001 From: Harmony Date: Tue, 14 May 2019 20:39:35 +0100 Subject: [PATCH 051/118] Build Hash and Version for error logs in the database --- sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql | 4 ++++ src/main/java/com/eu/habbo/core/ErrorLog.java | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql index 568aeff0..7f2fe6d3 100644 --- a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql +++ b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql @@ -2,4 +2,8 @@ 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`; + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file 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(); } } From 8547c452fa93ad6d50a1325a4bf875e0cdd95ed0 Mon Sep 17 00:00:00 2001 From: Harmony Date: Tue, 14 May 2019 20:44:41 +0100 Subject: [PATCH 052/118] Build Hash on the console info command --- .../com/eu/habbo/core/consolecommands/ConsoleInfoCommand.java | 4 ++++ 1 file changed, 4 insertions(+) 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()); From 766a24c1551a47453befe01d5953ec3c113a70d4 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 17:36:41 +0100 Subject: [PATCH 053/118] Added hotel.bot.butler.reachdistance config to ButlerBot. This will allow the bot to give an item without walking next to the player. --- .../eu/habbo/habbohotel/bots/ButlerBot.java | 12 +++++++++-- .../runnables/RoomUnitWalkToRoomUnit.java | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) 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/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index 69acc945..75f4c74e 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) { From efe1fd2258279abaf57b9c49781cc4b6d30a77b9 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 18:00:18 +0100 Subject: [PATCH 054/118] Fix NullPointerException in WiredEffectMoveFurniTowards --- .../wired/effects/WiredEffectMoveFurniTowards.java | 4 ++++ 1 file changed, 4 insertions(+) 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()); From 6f4105ceb93a52e3241ae681a36356a47bddc266 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 18:00:43 +0100 Subject: [PATCH 055/118] Fix NullPointerException in Room getStackHeight --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 da90908c..8293aa9e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4294,7 +4294,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); From 57b13360ce002c602f40dcbb906aa9b6cda24374 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 18:09:06 +0100 Subject: [PATCH 056/118] Fix NullPointerException in InteractionSwitch --- .../habbo/habbohotel/items/interactions/InteractionSwitch.java | 3 +++ 1 file changed, 3 insertions(+) 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..7072cb8c 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 @@ -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; From 0e4e492cac7df56a9d92fc9ce1522f42164502b4 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 19:32:47 +0100 Subject: [PATCH 057/118] Fix NullPointerException in RemoveFloorItemTask --- .../com/eu/habbo/threading/runnables/RemoveFloorItemTask.java | 3 +++ 1 file changed, 3 insertions(+) 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); From ea5811800d100e1504bd725d5af893808eb5a5a9 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 19:48:02 +0100 Subject: [PATCH 058/118] Fix NumberFormatException in InteractionFreezeBlock --- .../interactions/games/freeze/InteractionFreezeBlock.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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) { From 6f0c2fa8aa3c7ac538c84838a312da059218ab02 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Wed, 15 May 2019 15:25:29 -0400 Subject: [PATCH 059/118] Fix #79 --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 1 + 1 file changed, 1 insertion(+) 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 8293aa9e..f02726dd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1937,6 +1937,7 @@ public class Room implements Comparable, ISerialize, Runnable //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; From c616d4a82e581fe3c42696581541d34a64352246 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Wed, 15 May 2019 16:15:28 -0400 Subject: [PATCH 060/118] Add scripter manager and move ticket creation to manager --- sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql | 2 ++ .../habbohotel/catalog/CatalogManager.java | 5 +++-- .../habbohotel/modtool/ModToolManager.java | 2 +- .../habbo/habbohotel/modtool/ScripterEvent.java | 16 ++++++++++++++++ .../habbohotel/modtool/ScripterManager.java | 17 +++++++++++++++++ .../AmbassadorAlertCommandEvent.java | 3 ++- .../catalog/RequestCatalogPageEvent.java | 3 ++- .../catalog/marketplace/SellItemEvent.java | 5 +++-- .../incoming/guilds/RequestGuildBuyEvent.java | 3 ++- .../incoming/modtool/ModToolAlertEvent.java | 3 ++- .../modtool/ModToolChangeRoomSettingsEvent.java | 3 ++- .../modtool/ModToolCloseTicketEvent.java | 3 ++- .../modtool/ModToolPickTicketEvent.java | 3 ++- .../modtool/ModToolReleaseTicketEvent.java | 3 ++- .../ModToolRequestIssueChatlogEvent.java | 3 ++- .../modtool/ModToolRequestRoomChatlogEvent.java | 3 ++- .../modtool/ModToolRequestRoomInfoEvent.java | 3 ++- .../ModToolRequestRoomUserChatlogEvent.java | 3 ++- .../modtool/ModToolRequestUserChatlogEvent.java | 3 ++- .../modtool/ModToolRequestUserInfoEvent.java | 3 ++- .../incoming/modtool/ModToolRoomAlertEvent.java | 3 ++- .../modtool/ModToolSanctionBanEvent.java | 3 ++- .../incoming/modtool/ModToolWarnEvent.java | 3 ++- .../navigator/RequestDeleteRoomEvent.java | 3 ++- .../incoming/rooms/RoomSettingsSaveEvent.java | 3 ++- .../incoming/rooms/items/CloseDiceEvent.java | 3 ++- .../rooms/items/PostItSaveDataEvent.java | 3 ++- .../rooms/users/RoomUserShoutEvent.java | 3 ++- .../incoming/rooms/users/RoomUserTalkEvent.java | 3 ++- .../rooms/users/RoomUserWhisperEvent.java | 3 ++- .../incoming/users/UserSaveLookEvent.java | 3 ++- 31 files changed, 92 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ScripterEvent.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ScripterManager.java diff --git a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql index 7f2fe6d3..f6e347dd 100644 --- a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql +++ b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql @@ -6,4 +6,6 @@ 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'); + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file 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 5cf07b5e..fdf764b8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -10,6 +10,7 @@ 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; @@ -1053,7 +1054,7 @@ public class CatalogManager 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; @@ -1187,7 +1188,7 @@ public class CatalogManager { 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)); + ScripterManager.scripterDetected(habbo.getClient(), Emulator.getTexts().getValue("scripter.warning.catalog.badge_display").replace("%username%", habbo.getClient().getHabbo().getHabboInfo().getUsername()).replace("%badge%", extradata)); extradata = "UMAD"; } 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/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/guilds/RequestGuildBuyEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/RequestGuildBuyEvent.java index d28961cf..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,6 +2,7 @@ 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; @@ -109,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/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/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/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/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/users/UserSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/UserSaveLookEvent.java index 8197ed57..86cf3b6b 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,6 +2,7 @@ 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; @@ -23,7 +24,7 @@ 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; } From 8254e7de6176d496e35384ce83bc1ebad3ff70a7 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 21:36:11 +0100 Subject: [PATCH 061/118] Fix NullPointerException when rank doesn't exist. Renamed some methods to be more descriptive. --- .../com/eu/habbo/habbohotel/commands/GiveRankCommand.java | 2 +- .../habbo/habbohotel/permissions/PermissionsManager.java | 8 ++++++-- .../java/com/eu/habbo/habbohotel/users/HabboInfo.java | 4 +++- .../habbo/habbohotel/users/inventory/BadgesComponent.java | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) 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/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/users/HabboInfo.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java index 3e1ffba3..15b6f22b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -80,6 +80,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"); @@ -514,7 +516,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); 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 16e56a7d..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,7 +41,7 @@ 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().getRank().getId()) { From eac697af58a14eeb079767da86d2ba0adc91efd2 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 22:18:00 +0100 Subject: [PATCH 062/118] Fixed WiredConditionNotMatchStatePosition --- .../WiredConditionNotMatchStatePosition.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) 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(); From efc3c46d0b7fe8d3f2e0ff98f6512240f2a4b55e Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 22:54:07 +0100 Subject: [PATCH 063/118] Fixed Teleport and OneWayGate able to make you leave the room. Added canLeaveRoomByDoor to RoomUnit. --- .../interactions/InteractionOneWayGate.java | 10 ++++----- .../interactions/InteractionTeleport.java | 3 +++ .../habbo/habbohotel/rooms/RoomManager.java | 1 + .../eu/habbo/habbohotel/rooms/RoomUnit.java | 11 +++++++++- .../teleport/TeleportActionFive.java | 22 ++++++++++++++----- 5 files changed, 36 insertions(+), 11 deletions(-) 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 eee7d780..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 @@ -91,15 +91,15 @@ public class InteractionOneWayGate extends HabboItem List onFail = new ArrayList(); onSuccess.add(() -> { + unit.setCanLeaveRoomByDoor(false); walkable = this.getBaseItem().allowWalk(); - room.updateTile(currentLocation); - room.sendComposer(new ItemIntStateComposer(this.getId(), 0).compose()); - unit.removeOverrideTile(currentLocation); - - unit.setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4)); + 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()); 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 7f83c904..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 @@ -103,6 +103,7 @@ public class InteractionTeleport extends HabboItem room.updateTile(currentLocation); tryTeleport(client, room); unit.removeOverrideTile(currentLocation); + unit.setCanLeaveRoomByDoor(true); }); onFail.add(() -> { @@ -112,12 +113,14 @@ public class InteractionTeleport extends HabboItem 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 { 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 06cbd713..66884b2f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -720,6 +720,7 @@ public class RoomManager 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) { 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 597afdab..b3c50e50 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -57,6 +57,7 @@ public class RoomUnit private boolean statusUpdate = false; private boolean invisible = false; private boolean lastCycleStatus = false; + private boolean canLeaveRoomByDoor = true; private final ConcurrentHashMap status; private final THashMap cacheable; @@ -383,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); } @@ -824,4 +825,12 @@ public class RoomUnit 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/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index be318de4..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 @@ -5,6 +5,10 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; 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 { @@ -22,8 +26,10 @@ 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; @@ -35,10 +41,16 @@ class TeleportActionFive implements Runnable if (tile != null) { - this.client.getHabbo().getRoomUnit().setGoalLocation(tile); - this.client.getHabbo().getRoomUnit().statusUpdate(true); - } + 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); From f7c42c055b66937553f2b4eecbcd95b789d70afc Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 23:01:37 +0100 Subject: [PATCH 064/118] Fix guild badge not showing when favorite changed. --- .../habbo/messages/incoming/guilds/GuildSetFavoriteEvent.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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()); } } From 566de33b6e7589fd03518619d2b8db9c8c2c570c Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 23:13:33 +0100 Subject: [PATCH 065/118] Fixed Crackable becoming walkable when exploded --- .../com/eu/habbo/threading/runnables/CrackableExplode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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..012a61bd 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java +++ b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java @@ -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()); } } From cfc65466713a9344920a04d31018a18cf0c4ae12 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 23:39:39 +0100 Subject: [PATCH 066/118] Fixed exchangeable exploit & item duplication exploit --- .../habbo/habbohotel/items/ItemManager.java | 2 +- .../items/interactions/InteractionFXBox.java | 2 +- .../InteractionPetBreedingNest.java | 2 +- .../catalog/recycler/RecycleEvent.java | 2 +- .../crafting/CraftingCraftSecretEvent.java | 2 +- .../rooms/items/PostItDeleteEvent.java | 2 +- .../rooms/items/RedeemClothingEvent.java | 2 +- .../incoming/rooms/items/RedeemItemEvent.java | 87 +++++++++++-------- .../rooms/items/ToggleFloorItemEvent.java | 2 +- .../rooms/pets/PetPackageNameEvent.java | 2 +- .../incoming/rooms/pets/PetUseItemEvent.java | 8 +- .../habbo/threading/runnables/OpenGift.java | 2 +- .../threading/runnables/PetEatAction.java | 2 +- .../runnables/QueryDeleteHabboItem.java | 11 ++- 14 files changed, 73 insertions(+), 55 deletions(-) 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..98c050c3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -660,7 +660,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/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/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/messages/incoming/catalog/recycler/RecycleEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java index ef8af017..3ca79b8e 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 @@ -51,7 +51,7 @@ public class RecycleEvent extends MessageHandler { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } else 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..38eaeadb 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 @@ -94,7 +94,7 @@ public class CraftingCraftSecretEvent extends MessageHandler { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); - Emulator.getThreading().run(new QueryDeleteHabboItem(item)); + Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } this.client.sendResponse(new InventoryRefreshComposer()); 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/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/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/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/PetUseItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java index c94745b9..6fd22971 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PetUseItemEvent.java @@ -103,7 +103,7 @@ public class PetUseItemEvent 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 PetUseItemEvent 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 PetUseItemEvent 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 PetUseItemEvent 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/threading/runnables/OpenGift.java b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java index 84d49be6..40b01146 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java +++ b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java @@ -53,7 +53,7 @@ public class OpenGift implements Runnable this.habbo.getClient().sendResponse(new InventoryRefreshComposer()); - Emulator.getThreading().run(new QueryDeleteHabboItem(this.item)); + 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); if (inside != null) 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) From f7559ef1ed3334890b07113209b48eaf6f0eaa50 Mon Sep 17 00:00:00 2001 From: Harmony Date: Thu, 16 May 2019 00:37:36 +0100 Subject: [PATCH 067/118] Fix Update SQL name from RC-1 to RC-2 to RC-2 to RC-3 --- sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql diff --git a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql b/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql deleted file mode 100644 index f6e347dd..00000000 --- a/sqlupdates/2_0_0-RC-1_TO_2_0_0-RC-2.sql +++ /dev/null @@ -1,11 +0,0 @@ -#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'); - -#END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file From 6f79afc9945f21a2d8b2eb0e3f6aff39246ea78e Mon Sep 17 00:00:00 2001 From: Harmony Date: Thu, 16 May 2019 00:38:51 +0100 Subject: [PATCH 068/118] Fix Update SQL name from RC-1 to RC-2 to RC-2 to RC-3 --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql 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..7435cb55 --- /dev/null +++ b/sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql @@ -0,0 +1,11 @@ +#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'); + + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file From 2842e8993ab81b631227d201180350e14cec4e74 Mon Sep 17 00:00:00 2001 From: Beny Date: Thu, 16 May 2019 10:15:33 +0100 Subject: [PATCH 069/118] Increased wired cooldown --- .../habbo/habbohotel/items/interactions/InteractionWired.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From 6f5806f3fdc2939aa43f0d00b42cd34dddcbffda Mon Sep 17 00:00:00 2001 From: Beny Date: Thu, 16 May 2019 10:15:52 +0100 Subject: [PATCH 070/118] Fixed NullPointerException in WiredEffectTeleport --- .../interactions/wired/effects/WiredEffectTeleport.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 11463890..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 @@ -120,8 +120,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect } 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); From 60536d9fdf828159d1a1904bff4d555e1a749836 Mon Sep 17 00:00:00 2001 From: Beny Date: Thu, 16 May 2019 10:27:06 +0100 Subject: [PATCH 071/118] Added roller glitch. See Issue #47 --- .../com/eu/habbo/habbohotel/rooms/Room.java | 22 +++++++++++++------ .../rooms/users/RoomUnitOnRollerComposer.java | 20 +++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) 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 f02726dd..aadeb5e2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1737,13 +1737,21 @@ public class Room implements Comparable, ISerialize, Runnable if (item != null && itemsNewTile.contains(item)) { - try - { - item.onWalkOn(unit, room, null); - } catch (Exception e) - { - Emulator.getLogging().logErrorLine(e); - } + 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); } } 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 70b79890..88833dc9 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; @@ -62,13 +63,18 @@ 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(new Runnable() { + @Override + public void 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; + } + } + }, 500); } else { From 49ed004ce297fa1fc2edd1c4318c1dd1f3c07eeb Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 13:31:12 +0300 Subject: [PATCH 072/118] Fixes #41 --- .../interactions/wired/effects/WiredEffectTriggerStacks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From 829f71bc0f52eb0b2c45a64169ed4ebc264797dc Mon Sep 17 00:00:00 2001 From: Beny Date: Thu, 16 May 2019 12:41:14 +0100 Subject: [PATCH 073/118] Fix wrong height when rolling onto seat --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 aadeb5e2..6e0243ed 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1691,6 +1691,8 @@ public class Room implements Comparable, ISerialize, Runnable } } + HabboItem nextTileChair = this.getLowestChair(tileInFront); + for(RoomUnit unit : unitsOnTile) { if (rolledUnitIds.contains(unit.getId())) continue; @@ -1722,14 +1724,14 @@ public class Room implements Comparable, ISerialize, Runnable tile.setStackHeight(ridingUnit.getZ() + zOffset); rolledUnitIds.add(ridingUnit.getId()); updatedUnit.remove(ridingUnit); - messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tile, tile.getStackHeight(), room)); + 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), room)); + 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()) { From 9b15464fd1219aab3be4d66dd4cea24e4aaf1f9c Mon Sep 17 00:00:00 2001 From: Beny Date: Thu, 16 May 2019 13:26:05 +0100 Subject: [PATCH 074/118] Removed whitespace --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index 7435cb55..f6e347dd 100644 --- 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 @@ -1,11 +1,11 @@ #DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 - INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('commands.plugins.oldstyle', '0'); +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`; +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'); +INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('scripter.modtool.tickets', '1'); - #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file +#END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file From f3567f6714be21b0786ae449592014b8ac9bc76f Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 16:56:20 +0300 Subject: [PATCH 075/118] Add subscription boxes --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 4 +++ .../habbohotel/items/CrackableReward.java | 9 +++++++ .../habbo/habbohotel/items/ItemManager.java | 1 + .../items/RedeemableSubscriptionType.java | 24 +++++++++++++++++ .../interactions/InteractionCrackable.java | 26 +++++++++++++++++- .../InteractionRedeemableSubscriptionBox.java | 27 +++++++++++++++++++ .../threading/runnables/CrackableExplode.java | 2 +- 7 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java 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 index 7435cb55..9c90be02 100644 --- 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 @@ -8,4 +8,8 @@ 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`; + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ 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 98c050c3..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)); 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..ac58d5ce --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java @@ -0,0 +1,24 @@ +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) { + 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/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/threading/runnables/CrackableExplode.java b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java index 012a61bd..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); } From 8d7d5264e591b84e204e2733fe8fb8447c69bb8c Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 19:46:37 +0300 Subject: [PATCH 076/118] Closes #28 --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 3 +++ src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 8 ++++++++ 2 files changed, 11 insertions(+) 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 index f6e347dd..6769fd62 100644 --- 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 @@ -8,4 +8,7 @@ ADD COLUMN `build_hash` varchar(64) NOT NULL AFTER `version`; INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('scripter.modtool.tickets', '1'); +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.'); + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file 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 6e0243ed..66a347e5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3711,6 +3711,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) From 2b02012ecd5b7305404f70335f7f6e015f058302 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 20:11:11 +0300 Subject: [PATCH 077/118] Make invisible command toggleable --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 2 ++ .../habbohotel/commands/InvisibleCommand.java | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) 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 index 6769fd62..693b0804 100644 --- 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 @@ -11,4 +11,6 @@ INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('scripter.modtool.ticket 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.'); + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 \ No newline at end of file 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..8be82b99 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,14 @@ 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.RoomUnit; +import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +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; public class InvisibleCommand extends Command { @@ -17,10 +23,30 @@ public class InvisibleCommand extends Command { RoomUnit roomUnit = gameClient.getHabbo().getRoomUnit(); + if (roomUnit.isInvisible()) { + RoomLayout roomLayout = roomUnit.getRoom().getLayout(); + + roomUnit.setLocation(roomLayout.getDoorTile()); + roomUnit.clearStatus(); + roomUnit.clearWalking(); + roomUnit.setBodyRotation(RoomUserRotation.values()[roomLayout.getDoorDirection()]); + roomUnit.setHeadRotation(RoomUserRotation.values()[roomLayout.getDoorDirection()]); + 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; From 3161188c4593dc63e11de9eae7b50fde323d2a48 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 20:46:25 +0300 Subject: [PATCH 078/118] Fix invisible command in certain cases --- .../eu/habbo/habbohotel/commands/InvisibleCommand.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 8be82b99..876708b5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/InvisibleCommand.java @@ -3,13 +3,16 @@ 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 { @@ -26,11 +29,8 @@ public class InvisibleCommand extends Command if (roomUnit.isInvisible()) { RoomLayout roomLayout = roomUnit.getRoom().getLayout(); - roomUnit.setLocation(roomLayout.getDoorTile()); - roomUnit.clearStatus(); - roomUnit.clearWalking(); - roomUnit.setBodyRotation(RoomUserRotation.values()[roomLayout.getDoorDirection()]); - roomUnit.setHeadRotation(RoomUserRotation.values()[roomLayout.getDoorDirection()]); + new RoomUnitTeleport(roomUnit, roomUnit.getRoom(), roomLayout.getDoorTile().x, roomLayout.getDoorTile().y, roomLayout.getDoorTile().z, 0).run(); + roomUnit.setInvisible(false); roomUnit.setInRoom(true); From fc02123bd151f09541d02c08ff6913b90913ceb8 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Thu, 16 May 2019 21:01:11 +0300 Subject: [PATCH 079/118] Fix RedeemableSubscriptionType NullPointer --- .../eu/habbo/habbohotel/items/RedeemableSubscriptionType.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java b/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java index ac58d5ce..e16cf981 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/RedeemableSubscriptionType.java @@ -12,6 +12,8 @@ public enum RedeemableSubscriptionType { } public static RedeemableSubscriptionType fromString(String subscriptionType) { + if (subscriptionType == null) return null; + switch (subscriptionType) { case "hc": return HABBO_CLUB; From 59f5b406dee216f82e87d4a93156219cf995bae1 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Thu, 16 May 2019 19:39:07 -0400 Subject: [PATCH 080/118] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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 From 2e6d2b69a9f3cd990d02808d80b7d0403809154e Mon Sep 17 00:00:00 2001 From: Beny Date: Fri, 17 May 2019 07:33:30 +0100 Subject: [PATCH 081/118] Fixed a NullPointerException --- .../com/eu/habbo/habbohotel/rooms/Room.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 6e0243ed..a3f0048c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1718,14 +1718,16 @@ public class Room implements Comparable, ISerialize, Runnable boolean isRiding = false; if(unit.getRoomUnitType() == RoomUnitType.USER) { Habbo rollingHabbo = this.getHabbo(unit); - 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; + 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; + } } } From 7759f62a3d32fec6aa772b3c02c49f4cb402d5c8 Mon Sep 17 00:00:00 2001 From: Beny Date: Fri, 17 May 2019 07:35:53 +0100 Subject: [PATCH 082/118] Fixed a NullPointerException in WiredHandler --- src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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())) From caee5a331f493520b9d3412571328a4a79350448 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 12:21:55 +0300 Subject: [PATCH 083/118] Fix #84 --- src/main/java/com/eu/habbo/Emulator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index 6884bb63..048d6a6e 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -28,6 +28,7 @@ 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; @@ -90,6 +91,8 @@ public final class Emulator { try { + Locale.setDefault(new Locale("en")); + setBuild(); Emulator.stopped = false; ConsoleCommand.load(); From 1bf34edd21725f670eb85431e3093d542179eb1f Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 14:23:48 +0300 Subject: [PATCH 084/118] Fix #87 --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 90aaceda..cd57788c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3683,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 { From 737967eef47173d0ac9362577fc3cac4721db8d7 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 14:32:13 +0300 Subject: [PATCH 085/118] Fix #40 --- .../interactions/InteractionPressurePlate.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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()) From 001243c7e700efc05c98137890c5ef4cb2c08738 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 09:24:26 -0400 Subject: [PATCH 086/118] Prevent unredeemed clothing to be used by user --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 4 ++ .../habbohotel/commands/MimicCommand.java | 21 +++--- .../interactions/InteractionMannequin.java | 3 +- .../football/InteractionFootballGate.java | 6 +- .../com/eu/habbo/habbohotel/users/Habbo.java | 17 ++++- .../eu/habbo/habbohotel/users/HabboInfo.java | 15 ++++- .../incoming/users/UserSaveLookEvent.java | 7 ++ .../eu/habbo/messages/rcon/UpdateUser.java | 5 +- .../java/com/eu/habbo/util/FigureUtil.java | 65 ------------------- .../com/eu/habbo/util/figure/FigureUtil.java | 64 ++++++++++++++---- 10 files changed, 107 insertions(+), 100 deletions(-) delete mode 100644 src/main/java/com/eu/habbo/util/FigureUtil.java 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 index 223a8f75..c49c2386 100644 --- 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 @@ -17,4 +17,8 @@ INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('invisible.prevent.chat.err 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'; + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 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/items/interactions/InteractionMannequin.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java index 53c50531..29d4d6b4 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; @@ -93,7 +94,7 @@ public class InteractionMannequin extends HabboItem } } - client.getHabbo().getHabboInfo().setLook(look.substring(0, look.length() - 1)); + client.getHabbo().getHabboInfo().setLook(look.substring(0, look.length() - 1), true); room.sendComposer(new RoomUserDataComposer(client.getHabbo()).compose()); client.sendResponse(new UserDataComposer(client.getHabbo())); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java index b0e6950c..eb968519 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; @@ -102,7 +102,7 @@ public class InteractionFootballGate extends HabboItem Emulator.getPluginManager().fireEvent(lookEvent); if(!lookEvent.isCancelled()) { - habbo.getHabboInfo().setLook(lookEvent.newLook); + habbo.getHabboInfo().setLook(lookEvent.newLook, true); Emulator.getThreading().run(habbo.getHabboInfo()); habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo)); room.sendComposer(new RoomUserDataComposer(habbo).compose()); @@ -119,7 +119,7 @@ public class InteractionFootballGate extends HabboItem if(!lookEvent.isCancelled()) { habbo.getHabboStats().cache.put(CACHE_KEY, habbo.getHabboInfo().getLook()); - habbo.getHabboInfo().setLook(lookEvent.newLook); + habbo.getHabboInfo().setLook(lookEvent.newLook, true); Emulator.getThreading().run(habbo.getHabboInfo()); habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo)); room.sendComposer(new RoomUserDataComposer(habbo).compose()); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 9434ad33..bd7799b4 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 { @@ -512,4 +513,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 15b6f22b..d4bc2357 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -13,6 +13,7 @@ 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; @@ -215,7 +216,19 @@ public class HabboInfo implements Runnable return this.look; } - public void setLook(String look) { this.look = look; } + public void setLook(String look) { + this.setLook(look, false); + } + + public void setLook(String look, boolean stripForbidden) { + if (stripForbidden) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.id); + + if (habbo != null) look = FigureUtil.stripBlacklistedClothing(look, habbo.getForbiddenClothing()); + } + + this.look = look; + } public HabboGender getGender() { 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 86cf3b6b..53fffdb3 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 @@ -8,6 +8,7 @@ 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 { @@ -30,6 +31,12 @@ public class UserSaveLookEvent extends MessageHandler } String look = this.packet.readString(); + + if (FigureUtil.hasBlacklistedClothing(look, this.client.getHabbo().getForbiddenClothing())) { + ScripterManager.scripterDetected(this.client, "The user tried to wear clothing that they have not bought yet."); + return; + } + 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/rcon/UpdateUser.java b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java index 56e08f46..d661af1b 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; @@ -57,7 +58,7 @@ public class UpdateUser extends RCONMessage if (!json.look.isEmpty()) { - habbo.getHabboInfo().setLook(json.look); + habbo.getHabboInfo().setLook(json.look, json.strip_unredeemed_clothing); if(habbo.getClient() != null) { habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo).compose()); } @@ -160,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/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..9c20ac00 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,70 @@ 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 stripBlacklistedClothing(String figure, Set blacklist) { + StringJoiner joiner = new StringJoiner("."); + + for (String set : figure.split("\\.")) { + String[] pieces = set.split("-"); + + try { + if (pieces.length < 2 || !blacklist.contains(Integer.valueOf(pieces[1]))) { + joiner.add(set); + } + } catch (NumberFormatException ignored) { + joiner.add(set); + } + } + + return joiner.toString(); + } + public static String mergeFigures(String figure1, String figure2, String[] limitFigure1, String[] limitFigure2) { THashMap figureBits1 = getFigureBits(figure1); @@ -39,17 +75,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 +95,7 @@ public class FigureUtil { finalLook = new StringBuilder(finalLook.substring(0, finalLook.length() - 1)); } - + return finalLook.toString(); } -} +} \ No newline at end of file From df5c761d2d23ae82c5ccfbfa55ba049894160405 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 16:43:56 +0300 Subject: [PATCH 087/118] Fix #92 --- .../habbo/habbohotel/catalog/marketplace/MarketPlace.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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..645c261c 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"; From 7b8aeeec6af5a6bdb83e08a2206b37162af812c6 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 16:58:59 +0300 Subject: [PATCH 088/118] Fix rollers with setspeed 0. Closes #90 --- .../rooms/users/RoomUnitOnRollerComposer.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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 88833dc9..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 @@ -63,18 +63,14 @@ public class RoomUnitOnRollerComposer extends MessageComposer { RoomTile rollerTile = room.getLayout().getTile(this.roller.getX(), this.roller.getY()); - Emulator.getThreading().run(new Runnable() { - @Override - public void 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; - } + 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; } - }, 500); + }, this.room.getRollerSpeed() == 0 ? 250 : 500); } else { From 2f76811f418a1bff9f55f8e057a85f8f69203d89 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 17:30:26 +0300 Subject: [PATCH 089/118] Do not fill banzai tiles if a foreign locked tile exists --- .../games/battlebanzai/BattleBanzaiGame.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) 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 f4bafa2d..a3733c23 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 @@ -295,10 +295,10 @@ public class BattleBanzaiGame extends Game int y = item.getY(); List> filledAreas = new ArrayList<>(); - filledAreas.add(this.floodFill(x, y - 1, this.lockedTiles.get(teamColor), new ArrayList<>())); - filledAreas.add(this.floodFill(x, y + 1, this.lockedTiles.get(teamColor), new ArrayList<>())); - filledAreas.add(this.floodFill(x - 1, y, this.lockedTiles.get(teamColor), new ArrayList<>())); - filledAreas.add(this.floodFill(x + 1, y, this.lockedTiles.get(teamColor), new ArrayList<>())); + filledAreas.add(this.floodFill(x, y - 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x, y + 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x - 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x + 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); Optional> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size)); @@ -324,9 +324,9 @@ public class BattleBanzaiGame extends Game } } - private List floodFill(int x, int y, THashSet lockedTiles, List stack) + private List floodFill(int x, int y, THashSet lockedTiles, List stack, GameTeamColors color) { - if (this.isOutOfBounds(x, y)) return null; + if (this.isOutOfBounds(x, y) || this.isForeignLockedTile(x, y, color)) return null; RoomTile tile = this.room.getLayout().getTile((short)x, (short)y); @@ -335,10 +335,10 @@ public class BattleBanzaiGame extends Game stack.add(tile); List> result = new ArrayList<>(); - result.add(this.floodFill(x, y - 1, lockedTiles, stack)); - result.add(this.floodFill(x, y + 1, lockedTiles, stack)); - result.add(this.floodFill(x - 1, y, lockedTiles, stack)); - result.add(this.floodFill(x + 1, y, lockedTiles, stack)); + 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; @@ -368,6 +368,19 @@ public class BattleBanzaiGame extends Game 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() { for(GameTeam team : this.teams.values()) From 9116b4bf401bba846ba5af149a8ee3081cd5cb50 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 20:56:07 +0300 Subject: [PATCH 090/118] Fix catalog item pricing. Closes #9 --- .../habbohotel/catalog/CatalogManager.java | 355 ++++++++---------- .../outgoing/catalog/DiscountComposer.java | 23 +- 2 files changed, 181 insertions(+), 197 deletions(-) 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 fdf764b8..e7a1b066 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -1045,9 +1045,6 @@ public class CatalogManager } } - int totalCredits = 0; - int totalPoints = 0; - THashSet itemsList = new THashSet<>(); @@ -1073,199 +1070,157 @@ 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<>(); 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(); - } + for (int i = 0; i < amount; i++) { + habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp()); - habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp()); + 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 (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"); + 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)) - { - 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); - } + 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)) { + 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); + } } - //} } } } @@ -1394,4 +1349,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/messages/outgoing/catalog/DiscountComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/catalog/DiscountComposer.java index b16c34f1..2f23dae9 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,21 +6,26 @@ import com.eu.habbo.messages.outgoing.Outgoing; public class DiscountComposer extends MessageComposer { + public final static int MAXIMUM_ALLOWED_ITEMS = 100; + public final static int DISCOUNT_BATCH_SIZE = 6; + public final static int DISCOUNT_AMOUNT_PER_BATCH = 1; + public final static int MINIMUM_DISCOUNTS_FOR_BONUS = 1; + public final static int[] ADDITIONAL_DISCOUNT_THRESHOLDS = new int[]{40, 99}; + @Override public ServerMessage compose() { this.response.init(Outgoing.DiscountComposer); - this.response.appendInt(100); // maximum allowed to buy + 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(6); // free every x - - this.response.appendInt(1); - this.response.appendInt(1); - - this.response.appendInt(2); // array count for additional extras - this.response.appendInt(40); //extra free at 40 - this.response.appendInt(99); //extra free at 99 + this.response.appendInt(ADDITIONAL_DISCOUNT_THRESHOLDS.length); + for (int threshold : ADDITIONAL_DISCOUNT_THRESHOLDS) { + this.response.appendInt(threshold); + } return this.response; } From 22ab7d7e992adcde37bbcfad8f8f1778f27f9fc1 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 21:10:05 +0300 Subject: [PATCH 091/118] Remove `final` from discount configurations --- .../messages/outgoing/catalog/DiscountComposer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 2f23dae9..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,11 +6,11 @@ import com.eu.habbo.messages.outgoing.Outgoing; public class DiscountComposer extends MessageComposer { - public final static int MAXIMUM_ALLOWED_ITEMS = 100; - public final static int DISCOUNT_BATCH_SIZE = 6; - public final static int DISCOUNT_AMOUNT_PER_BATCH = 1; - public final static int MINIMUM_DISCOUNTS_FOR_BONUS = 1; - public final static int[] ADDITIONAL_DISCOUNT_THRESHOLDS = new int[]{40, 99}; + 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() From 66bab74a10fd7886cc173f5d537705feafb5851d Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 21:22:27 +0300 Subject: [PATCH 092/118] Make discounts configurable from database --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 6 ++++++ src/main/java/com/eu/habbo/plugin/PluginManager.java | 7 +++++++ 2 files changed, 13 insertions(+) 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 index c49c2386..35f7b2c6 100644 --- 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 @@ -21,4 +21,10 @@ INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('commands.error.cmd_mimic.f 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'); + #END DATABASE UPDATE: 2.0.0 RC-2 -> 2.0.0 RC-3 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"); From 487ad76ee2d76593318673e88557ffb78d7e612a Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Fri, 17 May 2019 23:07:22 +0300 Subject: [PATCH 093/118] Fix unseen item count not appearing. Closes #18 --- .../achievements/AchievementManager.java | 2 + .../habbohotel/catalog/CatalogManager.java | 31 +++++++- .../com/eu/habbo/habbohotel/users/Habbo.java | 1 + .../inventory/AddHabboItemComposer.java | 73 ++++++++++++++++--- .../outgoing/users/AddUserBadgeComposer.java | 2 +- 5 files changed, 95 insertions(+), 14 deletions(-) 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/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java index e7a1b066..4c9c0f3d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -41,6 +41,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.*; import java.util.*; +import java.util.stream.Collectors; public class CatalogManager { @@ -1077,7 +1078,9 @@ public class CatalogManager 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++) { habbo.getHabboStats().addLtdLog(item.getId(), Emulator.getIntUnixTimestamp()); @@ -1105,6 +1108,12 @@ public class CatalogManager 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); } @@ -1144,6 +1153,12 @@ public class CatalogManager 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())) { @@ -1256,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)); @@ -1274,6 +1287,10 @@ public class CatalogManager } } + if (!purchasedEvent.badges.isEmpty() && !unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) { + unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>()); + } + for (String b : purchasedEvent.badges) { HabboBadge badge = new HabboBadge(0, b, 0, habbo); @@ -1285,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); 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 bd7799b4..f5c3a2fb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -414,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"); 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/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; } From a413bfb0c655c465419de70251f594f84fb496a2 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 11:11:18 +0300 Subject: [PATCH 094/118] Fix unseen item count with badges in catalogue --- .../java/com/eu/habbo/habbohotel/catalog/CatalogManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4c9c0f3d..edaedd7e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -1287,7 +1287,7 @@ public class CatalogManager } } - if (!purchasedEvent.badges.isEmpty() && !unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BOT)) { + if (!purchasedEvent.badges.isEmpty() && !unseenItems.containsKey(AddHabboItemComposer.AddHabboItemCategory.BADGE)) { unseenItems.put(AddHabboItemComposer.AddHabboItemCategory.BADGE, new ArrayList<>()); } From b408d59b05c2c3cf4eb3fdce7e8bbc9216bd4259 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 13:38:30 +0300 Subject: [PATCH 095/118] Fix placing furni from gifts to a room. Closes #55 --- .../catalog/marketplace/MarketPlace.java | 7 ++- .../eu/habbo/habbohotel/users/HabboItem.java | 15 ++++++ .../users/inventory/ItemsComponent.java | 2 +- .../catalog/recycler/RecycleEvent.java | 2 +- .../crafting/CraftingCraftItemEvent.java | 2 +- .../crafting/CraftingCraftSecretEvent.java | 2 +- .../rooms/items/PostItPlaceEvent.java | 3 +- .../rooms/items/RoomPlaceItemEvent.java | 8 +-- .../inventory/InventoryItemsComposer.java | 2 +- .../InventoryUpdateItemComposer.java | 5 +- .../items/PresentItemOpenedComposer.java | 4 +- .../habbo/threading/runnables/OpenGift.java | 51 +++++++++++++++++-- 12 files changed, 81 insertions(+), 22 deletions(-) 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 645c261c..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 @@ -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/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java index 68aa8ba2..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; @@ -508,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/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/messages/incoming/catalog/recycler/RecycleEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleEvent.java index 3ca79b8e..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,7 +50,7 @@ public class RecycleEvent extends MessageHandler for (HabboItem item : items) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); + this.client.sendResponse(new RemoveHabboItemComposer(item.getGiftAdjustedId())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } } 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 38eaeadb..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,7 +93,7 @@ public class CraftingCraftSecretEvent extends MessageHandler for (HabboItem item : habboItems) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); - this.client.sendResponse(new RemoveHabboItemComposer(item.getId())); + 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/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/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/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/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/threading/runnables/OpenGift.java b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java index 40b01146..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)); - this.habbo.getClient().sendResponse(new InventoryRefreshComposer()); - 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<>(); + + 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)); } } From 8161e28411899843b94f39caa7d7046af587c28e Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 18 May 2019 14:14:21 +0100 Subject: [PATCH 096/118] Fixed a NullPointerException in calculateTileState --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cd57788c..b499c6f0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -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; From 75985a3696802abba07805b64198baf1d8925f6a Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 18 May 2019 14:14:58 +0100 Subject: [PATCH 097/118] Fixed a IllegalArgumentException in WiredEffectBotWalkToFurni --- .../effects/WiredEffectBotWalkToFurni.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) 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++; + } } } } From 1eddce95460182564c1226273f83b28689f4726f Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 18 May 2019 14:16:11 +0100 Subject: [PATCH 098/118] Fixed wrong error displaying in RedeemVoucherErrorComposer --- .../messages/outgoing/catalog/RedeemVoucherErrorComposer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } } From bfefe5887cb11f6533b9949b86c1764718cb8fcf Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 18 May 2019 14:17:27 +0100 Subject: [PATCH 099/118] Fixed NullPointerException in TradeAcceptEvent --- .../eu/habbo/messages/incoming/trading/TradeAcceptEvent.java | 4 ++++ 1 file changed, 4 insertions(+) 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) From b9e573ae343f32dcd49f540a40ee9ada44ed7c90 Mon Sep 17 00:00:00 2001 From: Beny Date: Sat, 18 May 2019 14:21:09 +0100 Subject: [PATCH 100/118] Removed users with rights able to pull switches from far away --- .../habbo/habbohotel/items/interactions/InteractionSwitch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7072cb8c..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 From 57bb88bc17109724ebdbe6f0469d6879dbbf3e1e Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 16:44:12 +0300 Subject: [PATCH 101/118] Prevent group join button reappearing after guild update --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 b499c6f0..b800d9a7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -5095,12 +5095,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())); } } From be7fc169352ac0d8a5f06a4819b4b87484f7e55f Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 16:59:41 +0300 Subject: [PATCH 102/118] Fix disappearing staff picked & public rooms. Closes #96 --- .../com/eu/habbo/habbohotel/GameEnvironment.java | 1 + .../habbohotel/navigation/NavigatorManager.java | 8 +++++++- .../com/eu/habbo/habbohotel/rooms/RoomManager.java | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java index a9097efe..09d5aec1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java +++ b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java @@ -71,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); 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/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 66884b2f..c2fd8b37 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -1598,6 +1598,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<>(); From 76f5bd1810b6e960d36c762be5d346aa49dfa5ca Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 18:32:13 +0300 Subject: [PATCH 103/118] Trigger onWalkOff when moving a furni from under a RoomUnit --- .../interactions/InteractionDefault.java | 17 ++++++++++++++ .../items/interactions/InteractionWater.java | 2 ++ .../com/eu/habbo/habbohotel/rooms/Room.java | 22 +++++++++++++++++++ .../eu/habbo/habbohotel/rooms/RoomTile.java | 6 +++++ 4 files changed, 47 insertions(+) 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/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/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index b800d9a7..8bccab0a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -5696,5 +5696,27 @@ public class Room implements Comparable, ISerialize, Runnable 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/RoomTile.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java index c284d37a..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,7 @@ 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; @@ -233,4 +235,8 @@ public class RoomTile 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 From 0fbebc5ac83b6a434a85a67ad176cac2dd5edf65 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 18:40:45 +0300 Subject: [PATCH 104/118] Fix a NullPointerException in InteractionBattleBanzaiPuck --- .../games/battlebanzai/InteractionBattleBanzaiPuck.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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()))); } From e15ea51c63d28504f2909f064abed7a033789b83 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 18:42:11 +0300 Subject: [PATCH 105/118] Fix a NullPointerException in RoomUnitWalkToRoomUnit --- .../eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 75f4c74e..3e233e96 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -108,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) { From 0e7350627875394e00845a6daabf268736d5a538 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 18:47:28 +0300 Subject: [PATCH 106/118] Fix a NullPointerException in Room.getItemsAt --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 b800d9a7..3bb46a63 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4047,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; ) @@ -4062,6 +4065,9 @@ public class Room implements Comparable, ISerialize, Runnable break; } + if (item == null) + continue; + if (item.getBaseItem().getType() != FurnitureType.FLOOR) continue; From 775d4298337ee777af2c829b22dde5fec567ec12 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 21:21:27 +0300 Subject: [PATCH 107/118] Fix ConcurrentModificationException in BB tile filling --- .../games/battlebanzai/BattleBanzaiGame.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 a3733c23..cc4139a5 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 @@ -18,6 +18,7 @@ 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; @@ -295,10 +296,11 @@ public class BattleBanzaiGame extends Game int y = item.getY(); List> filledAreas = new ArrayList<>(); - filledAreas.add(this.floodFill(x, y - 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x, y + 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x - 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x + 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); + THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); + 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)); @@ -335,10 +337,10 @@ public class BattleBanzaiGame extends Game 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)); + result.add(this.floodFill(x, y - 1, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x, y + 1, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x - 1, y, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x + 1, y, new THashSet<>(lockedTiles), stack, color)); if (result.contains(null)) return null; @@ -350,7 +352,7 @@ public class BattleBanzaiGame extends Game private boolean hasLockedTileAtCoordinates(int x, int y, THashSet lockedTiles) { - for (HabboItem item: lockedTiles) + for (HabboItem item : lockedTiles) { if (item.getX() == x && item.getY() == y) return true; } @@ -360,7 +362,7 @@ public class BattleBanzaiGame extends Game private boolean isOutOfBounds(int x, int y) { - for (HabboItem item: this.gameTiles.values()) + for (HabboItem item : this.gameTiles.values()) { if (item.getX() == x && item.getY() == y) return false; } From 3b10d8abc39b20699390c2e26b38f75548c42e2d Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 21:25:07 +0300 Subject: [PATCH 108/118] Remove unnecessary THashSet copyings --- .../habbohotel/games/battlebanzai/BattleBanzaiGame.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 cc4139a5..01650d44 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 @@ -337,10 +337,10 @@ public class BattleBanzaiGame extends Game stack.add(tile); List> result = new ArrayList<>(); - result.add(this.floodFill(x, y - 1, new THashSet<>(lockedTiles), stack, color)); - result.add(this.floodFill(x, y + 1, new THashSet<>(lockedTiles), stack, color)); - result.add(this.floodFill(x - 1, y, new THashSet<>(lockedTiles), stack, color)); - result.add(this.floodFill(x + 1, y, new THashSet<>(lockedTiles), stack, color)); + 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; From 25058296c2eca13f3e4f97f6196d31fbbb0a3cc3 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 22:03:11 +0300 Subject: [PATCH 109/118] Make BB tile filling threaded --- .../games/battlebanzai/BattleBanzaiGame.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) 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 01650d44..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 @@ -23,6 +23,8 @@ import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; public class BattleBanzaiGame extends Game { @@ -38,6 +40,8 @@ public class BattleBanzaiGame extends Game public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock", 1); + private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Emulator.getConfig().getInt("hotel.banzai.fill.threads", 2)); + private int tileCount; private int countDown; @@ -292,38 +296,41 @@ public class BattleBanzaiGame extends Game if (doNotCheckFill) return; - int x = item.getX(); - int y = item.getY(); + final int x = item.getX(); + final int y = item.getY(); - List> filledAreas = new ArrayList<>(); - THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); - 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)); + final List> filledAreas = new ArrayList<>(); + final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); - Optional> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size)); + 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)); - if (largestAreaOfAll.isPresent()) - { - for (RoomTile tile: largestAreaOfAll.get()) + Optional> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size)); + + if (largestAreaOfAll.isPresent()) { - Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny(); + 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); + tileItem.ifPresent(habboItem -> { + this.tileLocked(teamColor, habboItem, habbo, true); - habboItem.setExtradata((2 + (teamColor.type * 3) + 3) + ""); - this.room.updateItem(habboItem); - }); + 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()); + } } - - 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) From a8ac6cd65e90a01cdcfca4bd5f46398630266ec6 Mon Sep 17 00:00:00 2001 From: KrewsOrg Date: Sun, 19 May 2019 01:39:05 +0100 Subject: [PATCH 110/118] Update Version Number to RC-3. --- src/main/java/com/eu/habbo/Emulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/Emulator.java b/src/main/java/com/eu/habbo/Emulator.java index 048d6a6e..177be9a6 100644 --- a/src/main/java/com/eu/habbo/Emulator.java +++ b/src/main/java/com/eu/habbo/Emulator.java @@ -44,7 +44,7 @@ public final class Emulator public final static int BUILD = 0; - public final static String PREVIEW = "RC-2"; + public final static String PREVIEW = "RC-3"; public static final String version = "Arcturus Morningstar"+ " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW; From 2bada071ed5dbc037242fd15d4b5f46770d79835 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 19 May 2019 21:43:11 +0100 Subject: [PATCH 111/118] Added config for stripping un-owned clothes clothing.strip_unowned --- src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d4bc2357..bed421ad 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -221,7 +221,7 @@ public class HabboInfo implements Runnable } public void setLook(String look, boolean stripForbidden) { - if (stripForbidden) { + if (stripForbidden && Emulator.getConfig().getBoolean("clothing.strip_unowned", false)) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.id); if (habbo != null) look = FigureUtil.stripBlacklistedClothing(look, habbo.getForbiddenClothing()); From 0d55fe7ac0c8904fa6bf7c52b886f8a8531606b3 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 19 May 2019 22:11:42 +0100 Subject: [PATCH 112/118] Limit of 100 shown on mod tools to avoid crashing --- .../outgoing/modtool/ModToolComposer.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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 From dda8963c1e7375c0262163ea19bf97a05b4dd988 Mon Sep 17 00:00:00 2001 From: Beny Date: Sun, 19 May 2019 22:18:35 +0100 Subject: [PATCH 113/118] clothing.strip_unowned sql --- sqlupdates/2_0_0-RC-2_TO_2_0_0-RC-3.sql | 1 + 1 file changed, 1 insertion(+) 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 index 35f7b2c6..96f8f5b9 100644 --- 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 @@ -26,5 +26,6 @@ INSERT INTO `emulator_settings`(`key`, `value`) VALUES ('discount.batch.size', ' 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 From 1c73aa27a84a6cc8d41275d42f6044397e030785 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 20 May 2019 16:34:44 +0100 Subject: [PATCH 114/118] Removed stripBlacklistedClothing --- .../interactions/InteractionMannequin.java | 2 +- .../football/InteractionFootballGate.java | 4 ++-- .../eu/habbo/habbohotel/users/HabboInfo.java | 10 ---------- .../incoming/users/UserSaveLookEvent.java | 5 ----- .../com/eu/habbo/messages/rcon/UpdateUser.java | 2 +- .../com/eu/habbo/util/figure/FigureUtil.java | 18 ------------------ 6 files changed, 4 insertions(+), 37 deletions(-) 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 29d4d6b4..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 @@ -94,7 +94,7 @@ public class InteractionMannequin extends HabboItem } } - client.getHabbo().getHabboInfo().setLook(look.substring(0, look.length() - 1), true); + client.getHabbo().getHabboInfo().setLook(look.substring(0, look.length() - 1)); room.sendComposer(new RoomUserDataComposer(client.getHabbo()).compose()); client.sendResponse(new UserDataComposer(client.getHabbo())); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java index eb968519..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 @@ -102,7 +102,7 @@ public class InteractionFootballGate extends HabboItem Emulator.getPluginManager().fireEvent(lookEvent); if(!lookEvent.isCancelled()) { - habbo.getHabboInfo().setLook(lookEvent.newLook, true); + habbo.getHabboInfo().setLook(lookEvent.newLook); Emulator.getThreading().run(habbo.getHabboInfo()); habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo)); room.sendComposer(new RoomUserDataComposer(habbo).compose()); @@ -119,7 +119,7 @@ public class InteractionFootballGate extends HabboItem if(!lookEvent.isCancelled()) { habbo.getHabboStats().cache.put(CACHE_KEY, habbo.getHabboInfo().getLook()); - habbo.getHabboInfo().setLook(lookEvent.newLook, true); + habbo.getHabboInfo().setLook(lookEvent.newLook); Emulator.getThreading().run(habbo.getHabboInfo()); habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo)); room.sendComposer(new RoomUserDataComposer(habbo).compose()); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java index bed421ad..4c5cfef1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -217,16 +217,6 @@ public class HabboInfo implements Runnable } public void setLook(String look) { - this.setLook(look, false); - } - - public void setLook(String look, boolean stripForbidden) { - if (stripForbidden && Emulator.getConfig().getBoolean("clothing.strip_unowned", false)) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.id); - - if (habbo != null) look = FigureUtil.stripBlacklistedClothing(look, habbo.getForbiddenClothing()); - } - this.look = look; } 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 53fffdb3..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 @@ -32,11 +32,6 @@ public class UserSaveLookEvent extends MessageHandler String look = this.packet.readString(); - if (FigureUtil.hasBlacklistedClothing(look, this.client.getHabbo().getForbiddenClothing())) { - ScripterManager.scripterDetected(this.client, "The user tried to wear clothing that they have not bought yet."); - return; - } - 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/rcon/UpdateUser.java b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java index d661af1b..e96e9fc4 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java @@ -58,7 +58,7 @@ public class UpdateUser extends RCONMessage if (!json.look.isEmpty()) { - habbo.getHabboInfo().setLook(json.look, json.strip_unredeemed_clothing); + habbo.getHabboInfo().setLook(json.look); if(habbo.getClient() != null) { habbo.getClient().sendResponse(new UpdateUserLookComposer(habbo).compose()); } 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 9c20ac00..c30361d6 100644 --- a/src/main/java/com/eu/habbo/util/figure/FigureUtil.java +++ b/src/main/java/com/eu/habbo/util/figure/FigureUtil.java @@ -50,24 +50,6 @@ public class FigureUtil return false; } - public static String stripBlacklistedClothing(String figure, Set blacklist) { - StringJoiner joiner = new StringJoiner("."); - - for (String set : figure.split("\\.")) { - String[] pieces = set.split("-"); - - try { - if (pieces.length < 2 || !blacklist.contains(Integer.valueOf(pieces[1]))) { - joiner.add(set); - } - } catch (NumberFormatException ignored) { - joiner.add(set); - } - } - - return joiner.toString(); - } - public static String mergeFigures(String figure1, String figure2, String[] limitFigure1, String[] limitFigure2) { THashMap figureBits1 = getFigureBits(figure1); From ecf04c488d58026d5bb801da3d3635525095f31c Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 20 May 2019 18:35:20 +0100 Subject: [PATCH 115/118] Added two new plugin events - UserRespectedEvent and HabboAddedToRoomEvent --- .../eu/habbo/habbohotel/rooms/RoomManager.java | 7 +++++++ .../rooms/users/RoomUserGiveRespectEvent.java | 7 +++++++ .../events/users/HabboAddedToRoomEvent.java | 18 ++++++++++++++++++ .../events/users/UserRespectedEvent.java | 15 +++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/main/java/com/eu/habbo/plugin/events/users/HabboAddedToRoomEvent.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/users/UserRespectedEvent.java 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 c2fd8b37..b785c1e0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -41,8 +41,10 @@ import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer; +import com.eu.habbo.plugin.PluginManager; 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; @@ -50,6 +52,7 @@ import gnu.trove.map.hash.THashMap; import gnu.trove.procedure.TIntProcedure; import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; +import sun.plugin2.main.server.Plugin; import java.sql.*; import java.util.*; @@ -1072,6 +1075,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) 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/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; + } +} From cde96d3ed74ae3c5dc0361434d9808e0fd62f607 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 20 May 2019 18:39:21 +0100 Subject: [PATCH 116/118] Remove unused imports --- src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java | 3 --- 1 file changed, 3 deletions(-) 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 b785c1e0..aca433aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -11,7 +11,6 @@ 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.tag.TagGame; import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.items.interactions.InteractionWired; @@ -41,7 +40,6 @@ import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; import com.eu.habbo.messages.outgoing.rooms.promotions.RoomPromotionMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.MutedWhisperComposer; -import com.eu.habbo.plugin.PluginManager; import com.eu.habbo.plugin.events.navigator.NavigatorRoomCreatedEvent; import com.eu.habbo.plugin.events.rooms.RoomUncachedEvent; import com.eu.habbo.plugin.events.users.HabboAddedToRoomEvent; @@ -52,7 +50,6 @@ import gnu.trove.map.hash.THashMap; import gnu.trove.procedure.TIntProcedure; import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; -import sun.plugin2.main.server.Plugin; import java.sql.*; import java.util.*; From 4fc0a3c9a19d76bed3079b368b0402730633db6d Mon Sep 17 00:00:00 2001 From: Beny Date: Tue, 21 May 2019 19:09:54 +0100 Subject: [PATCH 117/118] SSO exploit fixed --- .../java/com/eu/habbo/habbohotel/users/HabboManager.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 64107ea0..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()) @@ -126,11 +126,10 @@ public class HabboManager 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) { From 732d876b9eb06841830f6132b7432c09eecf6179 Mon Sep 17 00:00:00 2001 From: Beny Date: Tue, 21 May 2019 19:39:49 +0100 Subject: [PATCH 118/118] Remove connection to camera server --- src/main/java/com/eu/habbo/networking/camera/CameraClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;