From 30490af9d2829e2cb8a66d6cccd8927351fe62b1 Mon Sep 17 00:00:00 2001 From: skeletor Date: Wed, 22 Jan 2020 04:32:11 -0500 Subject: [PATCH] fixed null pointer exception in timer reset wired --- .../wired/triggers/WiredTriggerRepeater.java | 15 ++++++++++++++- .../wired/triggers/WiredTriggerRepeaterLong.java | 15 ++++++++++++++- .../eu/habbo/habbohotel/wired/WiredHandler.java | 11 ++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java index 4476c515..d7fd07b4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java @@ -1,9 +1,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; @@ -17,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable { +public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset { public static final WiredTriggerType type = WiredTriggerType.PERIODICALLY; public static final int DEFAULT_DELAY = 20 * 500; @@ -123,4 +125,15 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy } } } + + @Override + public void resetTimer() { + this.counter = 0; + if (this.getRoomId() != 0) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (room != null && room.isLoaded()) { + WiredHandler.handle(this, null, room, new Object[]{this}); + } + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java index 5a0df5a1..7020988e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java @@ -1,9 +1,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; @@ -17,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable { +public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset { public static final int DEFAULT_DELAY = 20 * 5000; private static final WiredTriggerType type = WiredTriggerType.PERIODICALLY_LONG; private int repeatTime = DEFAULT_DELAY; @@ -117,4 +119,15 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements } } } + + @Override + public void resetTimer() { + this.counter = 0; + if (this.getRoomId() != 0) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (room != null && room.isLoaded()) { + WiredHandler.handle(this, null, room, new Object[]{this}); + } + } + } } 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 50232b1c..aa600682 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -418,14 +418,11 @@ public class WiredHandler { if (!room.isLoaded()) return; - THashSet triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.AT_GIVEN_TIME); - triggers.addAll(room.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY)); - triggers.addAll(room.getRoomSpecialTypes().getTriggers(WiredTriggerType.PERIODICALLY_LONG)); - if (triggers != null) { - for (InteractionWiredTrigger trigger : triggers) { - ((WiredTriggerReset) trigger).resetTimer(); + room.getRoomSpecialTypes().getTriggers().forEach(t-> { + if(t.getType() == WiredTriggerType.AT_GIVEN_TIME || t.getType() == WiredTriggerType.PERIODICALLY || t.getType() == WiredTriggerType.PERIODICALLY_LONG) { + ((WiredTriggerReset) t).resetTimer(); } - } + }); room.setLastTimerReset(Emulator.getIntUnixTimestamp()); }