RuneHive-Game
Loading...
Searching...
No Matches
ObjectPlacementEvent.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.game.task.Task;
4import com.runehive.game.world.object.CustomGameObject;
5
6/**
7 * An randomevent which places a temporary object.
8 *
9 * @author Daniel | Obey
10 */
11public class ObjectPlacementEvent extends Task {
12
13 /** The custom game object. */
14 private final CustomGameObject object;
15
16 /** The runnable. */
17 private final Runnable onDestination;
18
19 /** Constructs a new <code>ObjectReplacementEvent</code>. */
21 this(object, delay, () -> {
22 });
23 }
24
25 /** Constructs a new <code>ObjectReplacementEvent</code>. */
27 super(false, delay);
28 this.object = object;
29 this.onDestination = onDestination;
30 }
31
32 @Override
33 public void onSchedule() {
34 if (!object.isRegistered())
35 object.register();
36 }
37
38 @Override
39 public void execute() {
40 this.cancel();
41 }
42
43 @Override
44 public void onCancel(boolean logout) {
45 onDestination.run();
46
47 if (object.isRegistered()) {
48 object.unregister();
49 }
50 }
51
52}
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
int delay
The cyclic delay.
Definition Task.java:17
void execute()
A function representing the unit of work that will be carried out.
ObjectPlacementEvent(CustomGameObject object, int delay, Runnable onDestination)
Constructs a new ObjectReplacementEvent.
ObjectPlacementEvent(CustomGameObject object, int delay)
Constructs a new ObjectReplacementEvent.
void onSchedule()
A function executed on registration.
final CustomGameObject object
The custom game object.
void onCancel(boolean logout)
A function executed on cancellation.
Represents a static game object loaded from the map fs.