Merge branch 'dev' into 'dev'

Stankman Bot Fixes

See merge request morningstar/Arcturus-Community!318
This commit is contained in:
Harmonic 2020-10-08 15:24:43 -04:00
commit 134dc737e0
5 changed files with 66 additions and 54 deletions

View File

@ -12,6 +12,7 @@ import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.inventory.AddBotComposer;
import com.eu.habbo.messages.outgoing.inventory.RemoveBotComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
@ -48,13 +49,8 @@ public class BotManager {
}
public static void addBotDefinition(String type, Class<? extends Bot> botClazz) throws Exception {
if (botClazz.getDeclaredConstructor(ResultSet.class) == null) {
throw new Exception("Missing Bot(ResultSet) constructor!");
} else {
botClazz.getDeclaredConstructor(ResultSet.class).setAccessible(true);
botDefenitions.put(type, botClazz);
}
botClazz.getDeclaredConstructor(ResultSet.class).setAccessible(true);
botDefenitions.put(type, botClazz);
}
public boolean reload() {
@ -144,6 +140,7 @@ public class BotManager {
room.addBot(bot);
Emulator.getThreading().run(bot);
room.sendComposer(new RoomUsersComposer(bot).compose());
room.sendComposer(new RoomUserStatusComposer(bot.getRoomUnit()).compose());
habbo.getInventory().getBotsComponent().removeBot(bot);
habbo.getClient().sendResponse(new RemoveBotComposer(bot));
bot.onPlace(habbo, room);

View File

@ -69,13 +69,13 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
}
if (targetTile != null && targetTile.state != RoomTileState.INVALID) {
boolean hasHabbos = false;
for (Habbo habbo : room.getHabbosAt(targetTile)) {
hasHabbos = true;
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{entry.getKey()}));
boolean hasRoomUnits = false;
for (RoomUnit _roomUnit : room.getHabbosAndBotsAt(targetTile)) {
hasRoomUnits = true;
Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()}));
}
if (!hasHabbos) {
if (!hasRoomUnits) {
THashSet<RoomTile> refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, targetTile, targetTile.getStackHeight() - entry.getKey().getZ(), room).compose());
room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation());
@ -103,23 +103,23 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
String[] data = set.getString("wired_data").split("\t");
if (data.length >= 1) {
this.setDelay(Integer.valueOf(data[0]));
this.setDelay(Integer.parseInt(data[0]));
}
if (data.length >= 3) {
this.startRotation = RoomUserRotation.fromValue(Integer.valueOf(data[0]));
this.rotateAction = Integer.valueOf(data[1]);
this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[0]));
this.rotateAction = Integer.parseInt(data[1]);
int itemCount = Integer.valueOf(data[2]);
int itemCount = Integer.parseInt(data[2]);
if (itemCount > 0) {
for (int i = 3; i < data.length; i++) {
String[] subData = data[i].split(":");
if (subData.length == 2) {
HabboItem item = room.getHabboItem(Integer.valueOf(subData[0]));
HabboItem item = room.getHabboItem(Integer.parseInt(subData[0]));
if (item != null) {
this.items.put(item, RoomUserRotation.fromValue(Integer.valueOf(subData[1])));
this.items.put(item, RoomUserRotation.fromValue(Integer.parseInt(subData[1])));
}
}
}

View File

@ -82,7 +82,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
THashSet<HabboItem> items = new THashSet<HabboItem>();
THashSet<HabboItem> items = new THashSet<>();
for (HabboItem item : this.items) {
if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null)
@ -103,7 +103,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
RoomUserRotation lastDirection = lastDirections.get(item.getId());
// 1. Check if any user is within 3 tiles from the item
Habbo target = null; // closest found user
RoomUnit target = null; // closest found user
RoomLayout layout = room.getLayout();
boolean collided = false;
@ -128,12 +128,12 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
}
if (startTile != null && layout.tileExists(startTile.x, startTile.y)) {
THashSet<Habbo> habbosAtTile = room.getHabbosAt(startTile.x, startTile.y);
if (habbosAtTile.size() > 0) {
target = habbosAtTile.iterator().next();
THashSet<RoomUnit> roomUnitsAtTile = room.getHabbosAndBotsAt(startTile.x, startTile.y);
if (roomUnitsAtTile.size() > 0) {
target = roomUnitsAtTile.iterator().next();
if (i == 0) { // i = 0 means right next to it
collided = true;
Emulator.getThreading().run(new WiredCollissionRunnable(target.getRoomUnit(), room, new Object[]{item}));
Emulator.getThreading().run(new WiredCollissionRunnable(target, room, new Object[]{item}));
}
break;
}
@ -145,23 +145,23 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
continue;
if (target != null) {
if (target.getRoomUnit().getX() == item.getX()) {
if (item.getY() < target.getRoomUnit().getY())
if (target.getX() == item.getX()) {
if (item.getY() < target.getY())
moveDirection = RoomUserRotation.SOUTH;
else
moveDirection = RoomUserRotation.NORTH;
} else if (target.getRoomUnit().getY() == item.getY()) {
if (item.getX() < target.getRoomUnit().getX())
} else if (target.getY() == item.getY()) {
if (item.getX() < target.getX())
moveDirection = RoomUserRotation.EAST;
else
moveDirection = RoomUserRotation.WEST;
} else if (target.getRoomUnit().getX() - item.getX() > target.getRoomUnit().getY() - item.getY()) {
if (target.getRoomUnit().getX() - item.getX() > 0)
} else if (target.getX() - item.getX() > target.getY() - item.getY()) {
if (target.getX() - item.getX() > 0)
moveDirection = RoomUserRotation.EAST;
else
moveDirection = RoomUserRotation.WEST;
} else {
if (target.getRoomUnit().getY() - item.getY() > 0)
if (target.getY() - item.getY() > 0)
moveDirection = RoomUserRotation.SOUTH;
else
moveDirection = RoomUserRotation.NORTH;
@ -246,12 +246,12 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect {
String[] wiredData = set.getString("wired_data").split("\t");
if (wiredData.length >= 1) {
this.setDelay(Integer.valueOf(wiredData[0]));
this.setDelay(Integer.parseInt(wiredData[0]));
}
if (wiredData.length == 2) {
if (wiredData[1].contains(";")) {
for (String s : wiredData[1].split(";")) {
HabboItem item = room.getHabboItem(Integer.valueOf(s));
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);

View File

@ -75,7 +75,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
//handle movement
if (this.direction > 0) {
RoomUserRotation moveDirection = this.getMovementDirection();
boolean validMove = false;
boolean validMove;
RoomLayout layout = room.getLayout();
if (layout == null) return false;
@ -85,13 +85,13 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
);
if (newTile != null) {
boolean hasHabbos = false;
for (Habbo habbo : room.getHabbosAt(newTile)) {
hasHabbos = true;
WiredHandler.handle(WiredTriggerType.COLLISION, habbo.getRoomUnit(), room, new Object[]{item});
boolean hasRoomUnits = false;
for (RoomUnit _roomUnit : room.getHabbosAndBotsAt(newTile)) {
hasRoomUnits = true;
WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item});
}
if (!hasHabbos && room.getStackHeight(newTile.x, newTile.y, true, item) != Short.MAX_VALUE) {
if (!hasRoomUnits && room.getStackHeight(newTile.x, newTile.y, true, item) != Short.MAX_VALUE) {
java.awt.Rectangle rectangle = new Rectangle(newTile.x,
newTile.y,
item.getBaseItem().getWidth(),
@ -203,6 +203,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
this.rotation = Integer.parseInt(data[1]);
this.setDelay(Integer.parseInt(data[2]));
} catch (Exception e) {
System.out.println(e);
}
for (String s : data[3].split("\r")) {
@ -288,7 +289,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
/**
* Returns a new rotation for an item based on the wired options
*
* @param item
* @param item HabboItem
* @return new rotation
*/
private int getNewRotation(HabboItem item) {
@ -326,17 +327,13 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect {
movemementDirection = RoomUserRotation.WEST;
}
} else if (this.direction == 3) {
if (Emulator.getRandom().nextInt(2) == 1) {
movemementDirection = RoomUserRotation.NORTH;
} else {
if (Emulator.getRandom().nextInt(2) != 1) {
movemementDirection = RoomUserRotation.SOUTH;
}
} else if (this.direction == 4) {
movemementDirection = RoomUserRotation.SOUTH;
} else if (this.direction == 5) {
movemementDirection = RoomUserRotation.EAST;
} else if (this.direction == 6) {
movemementDirection = RoomUserRotation.NORTH;
} else if (this.direction == 7) {
movemementDirection = RoomUserRotation.WEST;
}

View File

@ -962,7 +962,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this));
}
@SuppressWarnings("NullableProblems")
@Override
public int compareTo(Room o) {
if (o.getUserCount() != this.getUserCount()) {
@ -1397,7 +1396,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
roomUserRolledEvent = new UserRolledEvent(null, null, null);
}
ArrayList<RoomUnit> unitsOnTile = new ArrayList<RoomUnit>(rollerTile.getUnits());
ArrayList<RoomUnit> unitsOnTile = new ArrayList<>(rollerTile.getUnits());
for (RoomUnit unit : rollerTile.getUnits()) {
if (unit.getRoomUnitType() == RoomUnitType.PET) {
@ -1946,7 +1945,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (extraData.length == 4) {
if (extraData[0].equalsIgnoreCase("1")) {
return Color.getHSBColor(Integer.valueOf(extraData[1]), Integer.valueOf(extraData[2]), Integer.valueOf(extraData[3]));
return Color.getHSBColor(Integer.parseInt(extraData[1]), Integer.parseInt(extraData[2]), Integer.parseInt(extraData[3]));
}
}
}
@ -2162,7 +2161,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
synchronized (this.games) {
for (Game game : this.games) {
if (game != null && gameType.isInstance(game)) {
if (gameType.isInstance(game)) {
return game;
}
}
@ -2900,6 +2899,25 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return habbos;
}
public THashSet<RoomUnit> getHabbosAndBotsAt(short x, short y) {
return this.getHabbosAndBotsAt(this.layout.getTile(x, y));
}
public THashSet<RoomUnit> getHabbosAndBotsAt(RoomTile tile) {
THashSet<RoomUnit> list = new THashSet<>();
for (Bot bot : this.getBotsAt(tile)) {
list.add(bot.getRoomUnit());
}
for(Habbo habbo : this.getHabbosAt(tile))
{
list.add(habbo.getRoomUnit());
}
return list;
}
public THashSet<Habbo> getHabbosOnItem(HabboItem item) {
THashSet<Habbo> habbos = new THashSet<>();
for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) {
@ -3130,7 +3148,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
ServerMessage prefixMessage = null;
if (Emulator.getPluginManager().isRegistered(UsernameTalkEvent.class, true)) {
UsernameTalkEvent usernameTalkEvent = (UsernameTalkEvent) Emulator.getPluginManager().fireEvent(new UsernameTalkEvent(habbo, roomChatMessage, chatType));
UsernameTalkEvent usernameTalkEvent = Emulator.getPluginManager().fireEvent(new UsernameTalkEvent(habbo, roomChatMessage, chatType));
if (usernameTalkEvent.hasCustomComposer()) {
prefixMessage = usernameTalkEvent.getCustomComposer();
}
@ -4397,7 +4415,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return FurnitureMovementError.NONE;
}
public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) throws Exception {
public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) {
boolean pluginHelper = false;
if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) {
FurniturePlacedEvent event = Emulator.getPluginManager().fireEvent(new FurniturePlacedEvent(item, owner, tile));
@ -4420,7 +4438,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
double height = tile.getStackHeight();
if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) {
FurnitureBuildheightEvent event = (FurnitureBuildheightEvent) Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, owner, 0.00, height));
FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, owner, 0.00, height));
if (event.hasChangedHeight()) {
height = event.getUpdatedHeight();
}
@ -4540,7 +4558,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
double height;
if (stackHelper.isPresent()) {
height = stackHelper.get().getExtradata().isEmpty() ? Double.valueOf("0.0") : (Double.valueOf(stackHelper.get().getExtradata()) / 100);
height = stackHelper.get().getExtradata().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtradata()) / 100);
} else if (item.equals(topItem) && tile.x == item.getX() && tile.y == item.getY()) {
height = item.getZ();
} else {
@ -4548,7 +4566,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) {
FurnitureBuildheightEvent event = (FurnitureBuildheightEvent) Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, height));
FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, height));
if (event.hasChangedHeight()) {
height = event.getUpdatedHeight();
}