fixed null pointer exception in timer reset wired

This commit is contained in:
skeletor 2020-01-22 04:32:11 -05:00 committed by Alejandro
parent d6a21ed131
commit 30490af9d2
3 changed files with 32 additions and 9 deletions

View File

@ -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});
}
}
}
}

View File

@ -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});
}
}
}
}

View File

@ -418,14 +418,11 @@ public class WiredHandler {
if (!room.isLoaded())
return;
THashSet<InteractionWiredTrigger> 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());
}