You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-19 15:06:19 +00:00
Merge pull request #250 from simoleo89/fix/wired-furni-selection-payloads
fix(wired): bound furni selection payloads
This commit is contained in:
+36
-6
@@ -92,21 +92,37 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||||
|
this.onPickUp();
|
||||||
String wiredData = set.getString("wired_data");
|
String wiredData = set.getString("wired_data");
|
||||||
|
if (wiredData == null || wiredData.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (wiredData.startsWith("{")) {
|
if (wiredData.startsWith("{")) {
|
||||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
JsonData data;
|
||||||
|
try {
|
||||||
|
data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||||
|
} catch (RuntimeException exception) {
|
||||||
|
this.onPickUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.all = data.all;
|
this.all = data.all;
|
||||||
this.furniSource = WiredFurniConditionInputGuard.normalizeFurniSource(data.furniSource);
|
this.furniSource = WiredFurniConditionInputGuard.normalizeFurniSource(data.furniSource);
|
||||||
|
|
||||||
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null) {
|
HabboItem item = room.getHabboItem(id);
|
||||||
this.items.add(item);
|
if (item != null) {
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String[] data = wiredData.split(":");
|
String[] data = wiredData.split(":");
|
||||||
|
|
||||||
@@ -117,8 +133,10 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
|
|||||||
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(data[1], WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(data[1], WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,6 +210,18 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int normalizeFurniSource(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTED:
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTOR:
|
||||||
|
case WiredSourceUtil.SOURCE_SIGNAL:
|
||||||
|
case WiredSourceUtil.SOURCE_TRIGGER:
|
||||||
|
return value;
|
||||||
|
default:
|
||||||
|
return WiredSourceUtil.SOURCE_TRIGGER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void refresh() {
|
private void refresh() {
|
||||||
THashSet<HabboItem> items = new THashSet<>();
|
THashSet<HabboItem> items = new THashSet<>();
|
||||||
|
|
||||||
|
|||||||
+24
-5
@@ -89,8 +89,11 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||||
this.items.clear();
|
this.onPickUp();
|
||||||
String wiredData = set.getString("wired_data");
|
String wiredData = set.getString("wired_data");
|
||||||
|
if (wiredData == null || wiredData.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (wiredData.startsWith("{")) {
|
if (wiredData.startsWith("{")) {
|
||||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||||
@@ -100,8 +103,10 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
|
|||||||
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null) {
|
HabboItem item = room.getHabboItem(id);
|
||||||
this.items.add(item);
|
if (item != null) {
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -111,8 +116,10 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
|
|||||||
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(data[1], WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(data[1], WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
|
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
|
||||||
@@ -179,6 +186,18 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int normalizeFurniSource(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTED:
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTOR:
|
||||||
|
case WiredSourceUtil.SOURCE_SIGNAL:
|
||||||
|
case WiredSourceUtil.SOURCE_TRIGGER:
|
||||||
|
return value;
|
||||||
|
default:
|
||||||
|
return WiredSourceUtil.SOURCE_TRIGGER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean hasAvatarOnItem(HabboItem item, Room room, Collection<Habbo> habbos, Collection<Bot> bots, Collection<Pet> pets) {
|
protected boolean hasAvatarOnItem(HabboItem item, Room room, Collection<Habbo> habbos, Collection<Bot> bots, Collection<Pet> pets) {
|
||||||
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
|
RoomTile baseTile = room.getLayout().getTile(item.getX(), item.getY());
|
||||||
if (baseTile == null) return false;
|
if (baseTile == null) return false;
|
||||||
|
|||||||
+32
-5
@@ -42,6 +42,10 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(WiredContext ctx) {
|
public boolean evaluate(WiredContext ctx) {
|
||||||
|
if (ctx == null || ctx.room() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
|
||||||
List<RoomUnit> userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
|
List<RoomUnit> userTargets = WiredSourceUtil.resolveUsers(ctx, this.userSource);
|
||||||
@@ -104,8 +108,11 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||||
this.items.clear();
|
this.onPickUp();
|
||||||
String wiredData = set.getString("wired_data");
|
String wiredData = set.getString("wired_data");
|
||||||
|
if (wiredData == null || wiredData.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (wiredData.startsWith("{")) {
|
if (wiredData.startsWith("{")) {
|
||||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||||
@@ -116,16 +123,20 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
|||||||
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for(int id : WiredFurniConditionInputGuard.sanitizeItemIds(data.itemIds, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null) {
|
HabboItem item = room.getHabboItem(id);
|
||||||
this.items.add(item);
|
if (item != null) {
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(wiredData, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
for (int id : WiredFurniConditionInputGuard.parseLegacyItemIds(wiredData, WiredManager.MAXIMUM_FURNI_SELECTION)) {
|
||||||
HabboItem item = room.getHabboItem(id);
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
|
this.furniSource = this.items.isEmpty() ? WiredSourceUtil.SOURCE_TRIGGER : WiredSourceUtil.SOURCE_SELECTED;
|
||||||
@@ -227,6 +238,22 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
|||||||
return (value == QUANTIFIER_ANY) ? QUANTIFIER_ANY : QUANTIFIER_ALL;
|
return (value == QUANTIFIER_ANY) ? QUANTIFIER_ANY : QUANTIFIER_ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int normalizeFurniSource(int value) {
|
||||||
|
switch (value) {
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTED:
|
||||||
|
case WiredSourceUtil.SOURCE_SELECTOR:
|
||||||
|
case WiredSourceUtil.SOURCE_SIGNAL:
|
||||||
|
case WiredSourceUtil.SOURCE_TRIGGER:
|
||||||
|
return value;
|
||||||
|
default:
|
||||||
|
return WiredSourceUtil.SOURCE_TRIGGER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int normalizeUserSource(int value) {
|
||||||
|
return WiredSourceUtil.isDefaultUserSource(value) ? value : WiredSourceUtil.SOURCE_TRIGGER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WiredConditionOperator operator() {
|
public WiredConditionOperator operator() {
|
||||||
return WiredConditionOperator.AND;
|
return WiredConditionOperator.AND;
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
|
||||||
|
|
||||||
|
import com.eu.habbo.habbohotel.wired.core.WiredSourceUtil;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class WiredConditionFurniSelectionPayloadGuardTest {
|
||||||
|
@Test
|
||||||
|
void furniHaveFurniBoundsFurniSources() {
|
||||||
|
WiredConditionFurniHaveFurni condition = new WiredConditionFurniHaveFurni(1, 1, null, "", 0, 0);
|
||||||
|
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_SELECTED, condition.normalizeFurniSource(WiredSourceUtil.SOURCE_SELECTED));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_SELECTOR, condition.normalizeFurniSource(WiredSourceUtil.SOURCE_SELECTOR));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_TRIGGER, condition.normalizeFurniSource(-10));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void furniHaveHabboBoundsFurniSources() {
|
||||||
|
WiredConditionFurniHaveHabbo condition = new WiredConditionFurniHaveHabbo(1, 1, null, "", 0, 0);
|
||||||
|
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_SIGNAL, condition.normalizeFurniSource(WiredSourceUtil.SOURCE_SIGNAL));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_TRIGGER, condition.normalizeFurniSource(8_000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void triggerOnFurniBoundsFurniUserSourcesAndQuantifier() {
|
||||||
|
WiredConditionTriggerOnFurni condition = new WiredConditionTriggerOnFurni(1, 1, null, "", 0, 0);
|
||||||
|
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_SELECTED, condition.normalizeFurniSource(WiredSourceUtil.SOURCE_SELECTED));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_TRIGGER, condition.normalizeFurniSource(77));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_CLICKED_USER, condition.normalizeUserSource(WiredSourceUtil.SOURCE_CLICKED_USER));
|
||||||
|
assertEquals(WiredSourceUtil.SOURCE_TRIGGER, condition.normalizeUserSource(WiredSourceUtil.SOURCE_SELECTED));
|
||||||
|
assertEquals(1, condition.normalizeQuantifier(1));
|
||||||
|
assertEquals(0, condition.normalizeQuantifier(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user