Merge branch 'buildheight_stackable_event' into 'dev'

Plugin events to make everything stackable if needed (in case of :buildheight)

See merge request morningstar/Arcturus-Community!281
This commit is contained in:
Harmonic 2020-09-19 13:16:11 -04:00
commit a886341c60
4 changed files with 78 additions and 9 deletions

View File

@ -3499,6 +3499,13 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (x < 0 || y < 0 || this.layout == null)
return calculateHeightmap ? Short.MAX_VALUE : 0.0;
if (Emulator.getPluginManager().isRegistered(FurnitureStackHeightEvent.class, true)) {
FurnitureStackHeightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureStackHeightEvent(x, y, this));
if(event.hasPluginHelper()) {
return calculateHeightmap ? event.getHeight() * 256.0D : event.getHeight();
}
}
double height = this.layout.getHeightAtSquare(x, y);
boolean canStack = true;
@ -4391,19 +4398,22 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) throws Exception {
boolean pluginHelper = false;
if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) {
Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, tile);
Emulator.getPluginManager().fireEvent(furniturePlacedEvent);
FurniturePlacedEvent event = Emulator.getPluginManager().fireEvent(new FurniturePlacedEvent(item, owner, tile));
if (furniturePlacedEvent.isCancelled())
if (event.isCancelled()) {
return FurnitureMovementError.CANCEL_PLUGIN_PLACE;
}
pluginHelper = event.hasPluginHelper();
}
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
FurnitureMovementError fits = furnitureFitsAt(tile, item, rotation);
if (!fits.equals(FurnitureMovementError.NONE)) {
if (!fits.equals(FurnitureMovementError.NONE) && !pluginHelper) {
return fits;
}
@ -4468,10 +4478,15 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor) {
RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY());
boolean pluginHelper = false;
if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) {
if (Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)).isCancelled())
FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile));
if(event.isCancelled()) {
return FurnitureMovementError.CANCEL_PLUGIN_MOVE;
}
pluginHelper = event.hasPluginHelper();
}
HabboItem topItem = this.getTopItemAt(tile.x, tile.y);
@ -4482,7 +4497,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
//Check if can be placed at new position
THashSet<RoomTile> occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation);
if (!stackHelper.isPresent()) {
if (!stackHelper.isPresent() && !pluginHelper) {
if (topItem != item) {
for (RoomTile t : occupiedTiles) {
HabboItem tileTopItem = this.getTopItemAt(t.x, t.y);

View File

@ -7,9 +7,8 @@ import com.eu.habbo.habbohotel.users.HabboItem;
public class FurnitureMovedEvent extends FurnitureUserEvent {
public final RoomTile oldPosition;
public final RoomTile newPosition;
private boolean pluginHelper;
public FurnitureMovedEvent(HabboItem furniture, Habbo habbo, RoomTile oldPosition, RoomTile newPosition) {
@ -17,5 +16,14 @@ public class FurnitureMovedEvent extends FurnitureUserEvent {
this.oldPosition = oldPosition;
this.newPosition = newPosition;
this.pluginHelper = false;
}
public void setPluginHelper(boolean helper) {
this.pluginHelper = helper;
}
public boolean hasPluginHelper() {
return this.pluginHelper;
}
}

View File

@ -7,11 +7,20 @@ import com.eu.habbo.habbohotel.users.HabboItem;
public class FurniturePlacedEvent extends FurnitureUserEvent {
public final RoomTile location;
private boolean pluginHelper;
public FurniturePlacedEvent(HabboItem furniture, Habbo habbo, RoomTile location) {
super(furniture, habbo);
this.location = location;
this.pluginHelper = false;
}
public void setPluginHelper(boolean helper) {
this.pluginHelper = helper;
}
public boolean hasPluginHelper() {
return this.pluginHelper;
}
}

View File

@ -0,0 +1,37 @@
package com.eu.habbo.plugin.events.furniture;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.plugin.Event;
public class FurnitureStackHeightEvent extends Event {
public final short x;
public final short y;
public final Room room;
private boolean pluginHelper;
private Double height;
public FurnitureStackHeightEvent(short x, short y, Room room) {
this.x = x;
this.y = y;
this.room = room;
this.pluginHelper = false;
this.height = 0.0D;
}
public void setPluginHelper(boolean helper) {
this.pluginHelper = helper;
}
public boolean hasPluginHelper() {
return this.pluginHelper;
}
public void setHeight(Double height) {
this.height = height;
}
public Double getHeight() {
return this.height;
}
}