Skip to content

Commit 41b6589

Browse files
author
ilm9001
committed
Interface
1 parent 5992151 commit 41b6589

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

src/main/java/com/ilm9001/nightclub/commands/LightCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void onBuild(Player player, String[] args) {
3838
return;
3939
}
4040
if (light != null) {
41-
light.off();
41+
light.off(new Color(0x000000));
4242
light.stop();
4343
}
4444
light = new Light(UUID.randomUUID(), "Unnamed-Light" + new Random().nextInt(), Location.getFromBukkitLocation(player.getLocation().add(0, 1, 0)),
@@ -235,7 +235,7 @@ public static void onTurnOn() {
235235
@CommandPermission("nightclub.light")
236236
public static void onTurnOff() {
237237
if (isUnloaded()) return;
238-
light.off();
238+
light.off(new Color(0x000000));
239239
}
240240
@Subcommand("flash")
241241
@Description("Flash light")

src/main/java/com/ilm9001/nightclub/light/Light.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@ToString
2525
@EqualsAndHashCode
26-
public class Light {
26+
public class Light implements LightInterface {
2727
private static final transient ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
2828
private static final transient int DELAY = 100; // run every x ms
2929
// annotations lol
@@ -95,7 +95,7 @@ public Light(UUID uuid, String name, Location location, double maxLength, double
9595
length -= 100.0 / this.timeToFadeToBlack;
9696
}
9797
if (length <= 0) {
98-
off();
98+
off(new Color(0x000000));
9999
timeToFade = 0;
100100
length = 0.1;
101101
}
@@ -139,7 +139,7 @@ public void load() {
139139
public void unload() {
140140
this.channel.getHandler().removeListener(this);
141141
this.speedChannel.getChannel().getHandler().removeSpeedListener(this);
142-
off();
142+
off(new Color(0x000000));
143143
stop();
144144
}
145145
/**
@@ -204,7 +204,7 @@ public void on(Color color) {
204204
/**
205205
* Turns Light off, sets length to 0.1 and sets timeToFade to 0
206206
*/
207-
public void off() {
207+
public void off(Color color) {
208208
lasers.forEach(LaserWrapper::stop);
209209
isOn = false;
210210
length = 0.1;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ilm9001.nightclub.light;
2+
3+
import java.awt.*;
4+
5+
public interface LightInterface {
6+
void on(Color color);
7+
8+
void off(Color color);
9+
10+
void flash(Color color);
11+
12+
void flashOff(Color color);
13+
14+
void start();
15+
16+
void stop();
17+
18+
void load();
19+
20+
void unload();
21+
}
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
package com.ilm9001.nightclub.light.event;
22

33
import com.ilm9001.nightclub.light.Light;
4+
import com.ilm9001.nightclub.light.LightInterface;
45

56
import java.awt.*;
67
import java.util.ArrayList;
78
import java.util.List;
89

910
public class LightEventHandler {
10-
private final List<Light> lights;
11-
private final List<Light> speedListeners;
11+
private final List<LightInterface> lights;
12+
private final List<LightInterface> speedListeners;
1213

1314
public LightEventHandler() {
1415
lights = new ArrayList<>();
1516
speedListeners = new ArrayList<>();
1617
}
1718

18-
public void addListener(Light light) {
19+
public void addListener(LightInterface light) {
1920
lights.add(light);
2021
}
21-
public void removeListener(Light light) {
22+
public void removeListener(LightInterface light) {
2223
lights.remove(light);
2324
}
24-
public void addSpeedListener(Light light) {
25+
public void addSpeedListener(LightInterface light) {
2526
speedListeners.add(light);
2627
}
27-
public void removeSpeedListener(Light light) {
28+
public void removeSpeedListener(LightInterface light) {
2829
speedListeners.remove(light);
2930
}
3031

3132
public void on(Color color) {
3233
lights.forEach(l -> l.on(color));
3334
}
3435
public void off(Color color) {
35-
lights.forEach(Light::off);
36+
lights.forEach(l -> l.off(color));
3637
}
3738
public void flash(Color color) {
3839
lights.forEach(l -> l.flash(color));
@@ -41,13 +42,21 @@ public void flashOff(Color color) {
4142
lights.forEach(l -> l.flashOff(color));
4243
}
4344
public void start() {
44-
lights.forEach(Light::start);
45+
lights.forEach(LightInterface::start);
4546
}
4647
public void stop() {
47-
lights.forEach(Light::stop);
48+
lights.forEach(LightInterface::stop);
4849
}
4950
public void setSpeed(double multiplier) {
50-
lights.forEach(l -> l.setSpeed(multiplier));
51-
speedListeners.forEach(l -> l.setSpeed(multiplier));
51+
lights.forEach(l -> {
52+
if (l instanceof Light) {
53+
((Light) l).setSpeed(multiplier);
54+
}
55+
});
56+
speedListeners.forEach(l -> {
57+
if (l instanceof Light) {
58+
((Light) l).setSpeed(multiplier);
59+
}
60+
});
5261
}
5362
}

0 commit comments

Comments
 (0)