Fixed Wired Change Direction, and Permissions Rights

This commit is contained in:
Stankman 2023-06-19 08:57:31 -05:00
parent d5036979c4
commit a6c6e8222f
6 changed files with 67 additions and 44 deletions

View File

@ -9,17 +9,15 @@ import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting;
import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredEffectType;
import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.incoming.wired.WiredSaveException;
import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.HashMap;
public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public final int PARAM_START_ROTATION = 0; public final int PARAM_START_DIRECTION = 0;
public final int PARAM_BLOCKED_ACTION = 1; public final int PARAM_BLOCKED_ACTION = 1;
public static final int ACTION_WAIT = 0; public static final int ACTION_WAIT = 0;
public static final int ACTION_TURN_RIGHT_45 = 1; public static final int ACTION_TURN_RIGHT_45 = 1;
@ -29,12 +27,21 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
public static final int ACTION_TURN_BACK = 5; public static final int ACTION_TURN_BACK = 5;
public static final int ACTION_TURN_RANDOM = 6; public static final int ACTION_TURN_RANDOM = 6;
private int defaultDirectionValue;
private int defaultBlockActionValue;
private boolean requiresUpdate = false;
private final HashMap<HabboItem, WiredChangeDirectionSetting> itemsSettings;
public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException { public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException {
super(set, baseItem); super(set, baseItem);
this.itemsSettings = new HashMap<>();
} }
public WiredEffectChangeFurniDirection(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { public WiredEffectChangeFurniDirection(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells); super(id, userId, item, extradata, limitedStack, limitedSells);
this.itemsSettings = new HashMap<>();
} }
@Override @Override
@ -43,10 +50,10 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
return false; return false;
} }
int startRotationValue = this.getWiredSettings().getIntegerParams().get(PARAM_START_ROTATION); int startDirectionValue = this.getWiredSettings().getIntegerParams().get(PARAM_START_DIRECTION);
int blockActionValue = this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION); int blockActionValue = this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION);
if(startRotationValue < 0 || startRotationValue > 7 || (startRotationValue % 2) != 0) { if(startDirectionValue < 0 || startDirectionValue > 7 || (startDirectionValue % 2) != 0) {
return false; return false;
} }
@ -54,14 +61,36 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
return false; return false;
} }
RoomUserRotation startRotation = RoomUserRotation.fromValue(startRotationValue); if(this.defaultDirectionValue != startDirectionValue) {
this.defaultDirectionValue = startDirectionValue;
this.requiresUpdate = true;
}
RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionValue);
if(this.requiresUpdate) {
for (WiredChangeDirectionSetting setting : this.itemsSettings.values()) {
setting.setDirection(startDirection);
}
this.requiresUpdate = false;
}
for(HabboItem item : this.getWiredSettings().getItems(room)) { for(HabboItem item : this.getWiredSettings().getItems(room)) {
WiredChangeDirectionSetting setting = new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startRotation); WiredChangeDirectionSetting setting = null;
if(!this.itemsSettings.containsKey(item)) {
this.itemsSettings.put(item, new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startDirection));
} else {
setting = this.itemsSettings.get(item);
}
if(setting == null) {
continue;
}
RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue()); RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue());
int count = 1; int count = 1;
while ((targetTile == null || targetTile.getState() == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) { while ((targetTile == null || targetTile.getState() == RoomTileState.INVALID || !room.tileWalkable(targetTile) || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) {
setting.setDirection(this.nextRotation(setting.getDirection())); setting.setDirection(this.nextDirection(setting.getDirection()));
RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue()); RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), setting.getDirection().getValue());
if (tile != null && tile.getState() != RoomTileState.INVALID) { if (tile != null && tile.getState() != RoomTileState.INVALID) {
@ -83,6 +112,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
} }
boolean hasRoomUnits = false; boolean hasRoomUnits = false;
THashSet<RoomTile> newOccupiedTiles = room.getLayout().getTilesAt(newTargetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); THashSet<RoomTile> newOccupiedTiles = room.getLayout().getTilesAt(newTargetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation());
for(RoomTile tile : newOccupiedTiles) { for(RoomTile tile : newOccupiedTiles) {
for (RoomUnit _roomUnit : room.getRoomUnits(tile)) { for (RoomUnit _roomUnit : room.getRoomUnits(tile)) {
@ -116,16 +146,16 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect {
} }
} }
private RoomUserRotation nextRotation(RoomUserRotation currentRotation) { private RoomUserRotation nextDirection(RoomUserRotation currentDirection) {
return switch (this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION)) { return switch (this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION)) {
case ACTION_TURN_BACK -> RoomUserRotation.fromValue(currentRotation.getValue()).getOpposite(); case ACTION_TURN_BACK -> RoomUserRotation.fromValue(currentDirection.getValue()).getOpposite();
case ACTION_TURN_LEFT_45 -> RoomUserRotation.counterClockwise(currentRotation); case ACTION_TURN_LEFT_45 -> RoomUserRotation.counterClockwise(currentDirection);
case ACTION_TURN_LEFT_90 -> RoomUserRotation.counterClockwise(RoomUserRotation.counterClockwise(currentRotation)); case ACTION_TURN_LEFT_90 -> RoomUserRotation.counterClockwise(RoomUserRotation.counterClockwise(currentDirection));
case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation); case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentDirection);
case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation)); case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentDirection));
case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8)); case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8));
case ACTION_WAIT -> currentRotation; case ACTION_WAIT -> currentDirection;
default -> currentRotation; default -> currentDirection;
}; };
} }

View File

@ -15,8 +15,8 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
super(set, baseItem); super(set, baseItem);
} }
public WiredTriggerHabboWalkOnFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { public WiredTriggerHabboWalkOnFurni(int id, int userId, Item item, String extraData, int limitedStack, int limitedSells) {
super(id, userId, item, extradata, limitedStack, limitedSells); super(id, userId, item, extraData, limitedStack, limitedSells);
} }
@Override @Override

View File

@ -34,7 +34,7 @@ public class PermissionGroup {
@Getter final Map<Integer, PermissionCurrencyTimer> timers; @Getter final Map<Integer, PermissionCurrencyTimer> timers;
public PermissionGroup(ResultSet set, Map<String, PermissionCommand> commandsAvailable) throws SQLException { public PermissionGroup(ResultSet set, Map<String, PermissionCommand> commandsAvailable, Map<String, PermissionRight> rightsAvailable) throws SQLException {
this.id = set.getInt("id"); this.id = set.getInt("id");
this.name = set.getString("name"); this.name = set.getString("name");
this.description = set.getString("description"); this.description = set.getString("description");
@ -50,7 +50,7 @@ public class PermissionGroup {
this.timers = new HashMap<>(); this.timers = new HashMap<>();
this.loadCommands(commandsAvailable); this.loadCommands(commandsAvailable);
this.loadRights(); this.loadRights(rightsAvailable);
this.loadTimers(); this.loadTimers();
log.info("Loaded " + this.name + " rank with " + this.commands.size() + " commands and " + this.rights.size() + " rights!"); log.info("Loaded " + this.name + " rank with " + this.commands.size() + " commands and " + this.rights.size() + " rights!");
@ -71,12 +71,13 @@ public class PermissionGroup {
} }
} }
private void loadRights() { private void loadRights(Map<String, PermissionRight> rightsAvailable) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM permission_group_rights WHERE group_id = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM permission_group_rights WHERE group_id = ?")) {
statement.setInt(1, this.id); statement.setInt(1, this.id);
try(ResultSet set = statement.executeQuery()) { try(ResultSet set = statement.executeQuery()) {
while (set.next()) { while (set.next()) {
PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(set.getString("name")); String rightName = set.getString("right_name");
PermissionRight right = rightsAvailable.values().stream().filter(rightAvailable -> rightAvailable.getName().equalsIgnoreCase(rightName)).findFirst().orElse(null);
this.rights.put(right, PermissionSetting.fromString(set.getString("setting_type"))); this.rights.put(right, PermissionSetting.fromString(set.getString("setting_type")));
} }
} }

View File

@ -43,7 +43,7 @@ public class PermissionsManager {
private void loadPermissionGroups() { private void loadPermissionGroups() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM permission_groups ORDER BY id ASC")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM permission_groups ORDER BY id ASC")) {
while (set.next()) { while (set.next()) {
PermissionGroup permissionGroup = new PermissionGroup(set, this.permissionCommands); PermissionGroup permissionGroup = new PermissionGroup(set, this.permissionCommands, this.permissionRights);
this.permissionGroups.put(permissionGroup.getId(), permissionGroup); this.permissionGroups.put(permissionGroup.getId(), permissionGroup);
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -8,7 +8,7 @@ import lombok.Setter;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class WiredChangeDirectionSetting { public class WiredChangeDirectionSetting {
private final int item_id; private final int itemId;
private int rotation; private int rotation;
@Setter private RoomUserRotation direction; @Setter private RoomUserRotation direction;

View File

@ -47,44 +47,36 @@ public class WiredHandler {
private static ObjectMapper objectMapper = null; private static ObjectMapper objectMapper = null;
public static boolean handle(WiredTriggerType triggerType, RoomUnit roomUnit, Room room, Object[] stuff) { public static boolean handle(WiredTriggerType triggerType, RoomUnit roomUnit, Room room, Object[] stuff) {
if (triggerType == WiredTriggerType.CUSTOM) return false; if (triggerType == WiredTriggerType.CUSTOM || !Emulator.isReady || room == null || !room.isLoaded() || room.getRoomSpecialTypes() == null) {
boolean talked = false;
if (!Emulator.isReady)
return false;
if (room == null)
return false;
if (!room.isLoaded())
return false;
if (room.getRoomSpecialTypes() == null)
return false; return false;
}
THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(triggerType); THashSet<InteractionWiredTrigger> triggers = room.getRoomSpecialTypes().getTriggers(triggerType);
if (triggers == null || triggers.isEmpty()) if (triggers == null || triggers.isEmpty()) {
return false; return false;
}
boolean talked = false;
long millis = System.currentTimeMillis(); long millis = System.currentTimeMillis();
THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<>(); THashSet<InteractionWiredEffect> effectsToExecute = new THashSet<>();
List<RoomTile> triggeredTiles = new ArrayList<>(); List<RoomTile> triggeredTiles = new ArrayList<>();
for (InteractionWiredTrigger trigger : triggers) { for (InteractionWiredTrigger trigger : triggers) {
RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY()); RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY());
if (triggeredTiles.contains(tile)) if (triggeredTiles.contains(tile)) {
continue; continue;
}
THashSet<InteractionWiredEffect> tEffectsToExecute = new THashSet<>(); THashSet<InteractionWiredEffect> tEffectsToExecute = new THashSet<>();
if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) { if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) {
effectsToExecute.addAll(tEffectsToExecute); effectsToExecute.addAll(tEffectsToExecute);
if (triggerType.equals(WiredTriggerType.SAY_SOMETHING)) if (triggerType.equals(WiredTriggerType.SAY_SOMETHING)) {
talked = true; talked = true;
}
triggeredTiles.add(tile); triggeredTiles.add(tile);
} }