Skip to content

Commit 31cb2b6

Browse files
committed
rings and movement effects working
1 parent 972edae commit 31cb2b6

File tree

7 files changed

+119
-70
lines changed

7 files changed

+119
-70
lines changed

Core/src/main/java/exposed/hydrogen/nightclub/commands/RingCommand.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public static void onBuild(CommandIssuer sender) {
5656
}
5757
UUID uuid = UUID.randomUUID();
5858
RingData ringData = RingData.builder()
59-
.linkedRingUUID("")
6059
.ringMovementData(new RingMovementData())
6160
.ringCount(4)
62-
.ringOffset(3)
61+
.ringLightCount(3)
62+
.ringOffset(0.8)
6363
.ringRotation(6)
6464
.ringSize(15)
6565
.ringSpacing(8)
@@ -105,7 +105,7 @@ public static void onLoad(CommandIssuer sender, String[] args) {
105105
List<CommandError> errors = isUnloaded();
106106
errors.add(args.length < 1 ? CommandError.TOO_LITTLE_ARGUMENTS : CommandError.VALID);
107107
if (errors.stream().noneMatch(error -> error == CommandError.LIGHTUNIVERSE_UNLOADED)) {
108-
errors.add(universe.getLight(args[0]) == null ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
108+
errors.add(universe.getRing(args[0]) == null ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
109109
}
110110
if (errors.stream().anyMatch(error -> error != CommandError.VALID && error != CommandError.RING_UNLOADED)) {
111111
sender.sendMessage(Util.formatErrors(errors));
@@ -132,7 +132,7 @@ public static void onClone(CommandIssuer sender, String[] args) {
132132
if (errors.stream().noneMatch(error -> error == CommandError.LIGHTUNIVERSE_UNLOADED)) {
133133
errors.add(universe.getLight(args[0]) == null ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
134134
}
135-
if (errors.stream().anyMatch(error -> error != CommandError.VALID && error != CommandError.LIGHT_UNLOADED)) {
135+
if (errors.stream().anyMatch(error -> error != CommandError.VALID && error != CommandError.RING_UNLOADED)) {
136136
sender.sendMessage(Util.formatErrors(errors));
137137
return;
138138
}
@@ -222,44 +222,42 @@ public static void onSetLocation(CommandIssuer sender, String[] args) {
222222
ring.start();
223223
}
224224

225-
@Subcommand("link")
226-
@Description("Link this ring to another ring")
227-
@CommandCompletion("@rings")
225+
@Subcommand("count")
226+
@CommandAlias("rc")
227+
@Description("Set ring count")
228228
@CommandPermission("nightclub.ring")
229-
public static void onSetLinkedRing(CommandIssuer sender, String[] args) {
230-
LightUniverseManager manager = Nightclub.getLightUniverseManager();
231-
LightUniverse universe = manager.getLoadedUniverse();
232-
233-
List<CommandError> errors = isUnloaded();
234-
errors.add(args.length < 1 ? CommandError.TOO_LITTLE_ARGUMENTS : CommandError.VALID);
235-
if (errors.stream().noneMatch(error -> error == CommandError.LIGHTUNIVERSE_UNLOADED)) {
236-
errors.add(universe.getLight(args[0]) == null ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
229+
public static void onRingCount(CommandIssuer sender, String[] args) {
230+
List<CommandError> errors = isUnloaded(args, 1);
231+
try {
232+
ring.getRingData().setRingCount(Util.parseNumber(args[0]).intValue());
233+
} catch (ParseException e) {
234+
errors.add(CommandError.INVALID_ARGUMENT);
237235
}
238-
if (errors.stream().anyMatch(error -> error != CommandError.VALID && error != CommandError.LIGHT_UNLOADED)) {
236+
if (errors.stream().anyMatch(error -> error != CommandError.VALID)) {
239237
sender.sendMessage(Util.formatErrors(errors));
240-
return;
241238
}
242-
243-
ring.getRingData().setLinkedRingUUID(universe.getRing(args[0]).getUniqueId().toString());
239+
ring.buildLasers();
244240
ring.start();
245241
}
246242

247-
@Subcommand("count")
248-
@CommandAlias("rc")
243+
@Subcommand("lightcount")
244+
@CommandAlias("lc")
249245
@Description("Set ring count")
250246
@CommandPermission("nightclub.ring")
251-
public static void onRingCount(CommandIssuer sender, String[] args) {
247+
public static void onRingLightCount(CommandIssuer sender, String[] args) {
252248
List<CommandError> errors = isUnloaded(args, 1);
253249
try {
254-
ring.getRingData().setRingCount(Util.parseNumber(args[0]).intValue());
250+
ring.getRingData().setRingLightCount(Util.parseNumber(args[0]).intValue());
255251
} catch (ParseException e) {
256252
errors.add(CommandError.INVALID_ARGUMENT);
257253
}
258254
if (errors.stream().anyMatch(error -> error != CommandError.VALID)) {
259255
sender.sendMessage(Util.formatErrors(errors));
260256
}
257+
ring.buildLasers();
261258
ring.start();
262259
}
260+
263261
@Subcommand("size")
264262
@CommandAlias("sz")
265263
@Description("Set ring size")
@@ -276,6 +274,7 @@ public static void onRingSize(CommandIssuer sender, String[] args) {
276274
}
277275
ring.start();
278276
}
277+
279278
@Subcommand("offset")
280279
@CommandAlias("os")
281280
@Description("Set ring offset from linked ring")

Core/src/main/java/exposed/hydrogen/nightclub/light/Light.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.gson.JsonArray;
44
import exposed.hydrogen.nightclub.Nightclub;
5-
import exposed.hydrogen.nightclub.json.JSONUtils;
65
import exposed.hydrogen.nightclub.light.data.*;
76
import exposed.hydrogen.nightclub.light.event.LightChannel;
87
import exposed.hydrogen.nightclub.light.event.LightSpeedChannel;
@@ -85,11 +84,17 @@ public Light(UUID uuid, String name, Location location, LightType type, LightCha
8584

8685
run = () -> {
8786
try {
88-
if (isZoomed ? zoomTime > 0 : zoomTime < 1) {
87+
if (isZoomed ? zoomTime < 1 : zoomTime > 0) {
8988
double duration = getData().getRingMovementData().getDuration();
9089
zoomTime = isZoomed ?
91-
zoomTime - duration >= 0 ? duration / 1000 / (DELAY / 10.0) : 1
92-
: zoomTime + duration <= 1 ? duration / 1000 / (DELAY / 10.0) : 1;
90+
zoomTime + duration / 1000 / (DELAY / 10.0)
91+
: zoomTime - duration / 1000 / (DELAY / 10.0);
92+
}
93+
if(zoomTime < 0 && !isZoomed) {
94+
zoomTime = 0;
95+
}
96+
if(zoomTime > 1 && isZoomed) {
97+
zoomTime = 1;
9398
}
9499
if (timeToFade > 0 && length > 0) {
95100
timeToFade--;
@@ -145,7 +150,6 @@ x value that is separated evenly for each laser. This pattern is then moved (as
145150
}
146151

147152
public void load() {
148-
this.setData(JSONUtils.addNewDataIfNull(this.getData()));
149153
this.channel.removeListener(this);
150154
this.speedChannel.getChannel().removeSpeedListener(this);
151155
this.channel.addListener(this);
@@ -306,7 +310,6 @@ public void flashOff(Color color) {
306310
public void ringZoom() {
307311
if (!isLoaded) return;
308312
isZoomed = !isZoomed;
309-
zoomTime = isZoomed ? 1 : 0;
310313
marker.setLocation(loc);
311314
marker.start(256);
312315
}

Core/src/main/java/exposed/hydrogen/nightclub/light/Ring.java

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import lombok.*;
99
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
1010

11-
import java.util.LinkedList;
12-
import java.util.List;
13-
import java.util.Random;
14-
import java.util.UUID;
11+
import java.util.*;
1512
import java.util.concurrent.Executors;
1613
import java.util.concurrent.ScheduledExecutorService;
1714

@@ -27,7 +24,7 @@ public class Ring {
2724
@Getter @Setter private RingData ringData;
2825
@Getter @Setter private LightType lightType;
2926

30-
private final transient List<LaserWrapper> lasers = new LinkedList<>();
27+
private final transient LinkedHashMap<Integer,List<LaserWrapper>> lasers;
3128
private transient double zoomTime = 0; // 0 to 1, current zoom time. does nothing if <=0
3229
private transient double rotationTime = 0; // current rotation time
3330
@Getter @Setter private transient double rotation = 0; // 0 to 360, degrees rotation
@@ -46,70 +43,106 @@ public Ring(UUID uniqueId, String name, Location location, RingData ringData, Li
4643
this.location = location;
4744
this.ringData = ringData;
4845
this.lightType = lightType;
46+
lasers = new LinkedHashMap<>();
4947
this.run = () -> {
50-
// Do nothing if no need to rotate
51-
if (rotationTime > 0) {
52-
double duration = getRingData().getRingRotation();
53-
zoomTime = zoomTime - duration/10;
54-
}
55-
if (isZoomed ? zoomTime > 0 : zoomTime < 1) {
48+
if (isZoomed ? zoomTime < 1 : zoomTime > 0) {
5649
double duration = getRingData().getRingMovementData().getDuration();
5750
zoomTime = isZoomed ?
58-
zoomTime - duration >= 0 ? duration / 1000 / (DELAY / 10.0) : 1
59-
: zoomTime + duration <= 1 ? duration / 1000 / (DELAY / 10.0) : 1;
51+
zoomTime + duration / 1000 / (DELAY / 10.0)
52+
: zoomTime - duration / 1000 / (DELAY / 10.0);
53+
}
54+
zoomTime = zoomTime < 0 && !isZoomed ? 0 : zoomTime;
55+
zoomTime = zoomTime > 1 && isZoomed ? 1 : zoomTime;
56+
57+
rotationTime = rotationTime > 45 ? 45 : rotationTime;
58+
rotationTime = rotationTime < -45 ? -45 : rotationTime;
59+
60+
if (rotationTime < 0.5 && rotationTime > -0.5) {
61+
rotationTime = 0;
62+
}
63+
if(rotationTime > 0.5 || rotationTime < -0.5) {
64+
rotationTime -= rotationTime/10;
65+
} else if(rotationTime < 0.5 && rotationTime > -0.5) {
66+
rotationTime += rotationTime/10;
6067
}
68+
6169
rotation = rotation + rotationTime;
6270
rotation = rotation % 360;
63-
List<Vector3D> ringEdgePoints = getRingData().calculateRingEdgePoints(this.location.toVector3D(), Math.toRadians(rotation));
64-
for (int i = 0; i < lasers.size(); i++) {
65-
LaserWrapper laser = lasers.get(i);
66-
Vector3D ringedgePoint = ringEdgePoints.get(i);
67-
Vector3D nextRingEdgePoint = ringEdgePoints.get((i + 1) % ringEdgePoints.size());
68-
Vector3D v1 = getRingData().getRingMovementData().calculateMovement(zoomTime);
69-
laser.setStart(this.location.clone().add(Location.fromVector3D(ringedgePoint.add(v1))));
70-
laser.setEnd(this.location.clone().add(Location.fromVector3D(nextRingEdgePoint.add(v1))));
71+
for (int ring = 0; ring < this.ringData.getRingCount(); ring++) {
72+
// a (invisible) "ray" the size of length, pointing towards the set pitch and yaw
73+
Vector3D v = new Vector3D(Math.toRadians(this.location.getYaw()), Math.toRadians(this.location.getPitch()))
74+
.normalize().scalarMultiply((ring * this.ringData.getRingSpacing()) / (zoomTime+1));
75+
76+
List<Vector3D> ringEdgePoints = RingData.calculateRingEdgePoints(this.location.toVector3D().add(v),
77+
Math.toRadians(rotation*(this.ringData.getRingOffset()+ring)), this.ringData.getRingLightCount(), this.ringData.getRingSize());
78+
79+
List<LaserWrapper> laserWrappers = lasers.get(ring);
80+
81+
for (int i = 0; i < laserWrappers.size(); i++) {
82+
LaserWrapper laser = laserWrappers.get(i);
83+
Vector3D ringedgePoint = ringEdgePoints.get(i);
84+
Vector3D nextRingEdgePoint = ringEdgePoints.get((i + 1) % ringEdgePoints.size());
85+
Vector3D v1 = getRingData().getRingMovementData().calculateMovement(zoomTime);
86+
87+
laser.setStart(this.location.clone().add(Location.fromVector3D(ringedgePoint.add(v1).add(v))));
88+
laser.setEnd(this.location.clone().add(Location.fromVector3D(nextRingEdgePoint.add(v1).add(v))));
89+
}
7190
}
7291
};
7392
}
7493

7594
public void buildLasers() {
76-
for(LaserWrapper laser : lasers) {
77-
laser.stop();
95+
for(List<LaserWrapper> laserWrappers : lasers.values()) {
96+
for(LaserWrapper laserWrapper : laserWrappers) {
97+
laserWrapper.stop();
98+
}
7899
}
79100
lasers.clear();
80-
List<Vector3D> ringEdgePoints = getRingData().calculateRingEdgePoints(this.location.toVector3D(), Math.toRadians(rotation));
81-
for (int i = 0; i < getRingData().getRingCount(); i++) {
82-
LaserWrapper laser;
83-
Vector3D ringedgePoint = ringEdgePoints.get(i);
84-
Vector3D nextRingEdgePoint = ringEdgePoints.get((i + 1) % ringEdgePoints.size());
85-
laser = Nightclub.getLaserFactory().build(Location.fromVector3D(ringedgePoint),Location.fromVector3D(nextRingEdgePoint), -1, 256, lightType);
86-
lasers.add(laser);
101+
for (int ring = 0; ring < this.ringData.getRingCount(); ring++) {
102+
List<Vector3D> ringEdgePoints = RingData.calculateRingEdgePoints(this.location.toVector3D(),
103+
Math.toRadians(rotation*(ring+1)), this.ringData.getRingLightCount(), this.ringData.getRingSize());
104+
List<LaserWrapper> laserWrappers = new LinkedList<>();
105+
for (int i = 0; i < ringData.getRingLightCount(); i++) {
106+
Vector3D ringedgePoint = ringEdgePoints.get(i);
107+
Vector3D nextRingEdgePoint = ringEdgePoints.get((i + 1) % ringEdgePoints.size());
108+
LaserWrapper laser = Nightclub.getLaserFactory().build(Location.fromVector3D(ringedgePoint),Location.fromVector3D(nextRingEdgePoint), -1, 256, lightType);
109+
laserWrappers.add(laser);
110+
}
111+
lasers.put(ring, laserWrappers);
87112
}
88113
}
89114

90115
public void start() {
91116
stop();
92-
for(LaserWrapper laser : lasers) {
93-
laser.start();
117+
for(List<LaserWrapper> laserWrappers : lasers.values()) {
118+
for(LaserWrapper laserWrapper : laserWrappers) {
119+
laserWrapper.start();
120+
}
94121
}
95122
executorService = Executors.newScheduledThreadPool(1);
96123
executorService.scheduleAtFixedRate(run, 0, DELAY, java.util.concurrent.TimeUnit.MILLISECONDS);
97124
}
98125

99126
public void stop() {
100127
executorService.shutdown();
101-
for(LaserWrapper laser : lasers) {
102-
laser.stop();
128+
for(List<LaserWrapper> laserWrappers : lasers.values()) {
129+
for(LaserWrapper laserWrapper : laserWrappers) {
130+
laserWrapper.stop();
131+
}
103132
}
104133
}
105134

106135
public void spin() {
107136
// Replicates beat sabers ring system which is random, TODO: Implement chroma support of customizable ring direction
108-
rotationTime = Math.min(random.nextBoolean() ? rotationTime + Math.sqrt(ringData.getRingRotation()) : rotationTime - Math.sqrt(ringData.getRingRotation()),45);
137+
rotationTime = random.nextBoolean() ? rotationTime + Math.sqrt(ringData.getRingRotation()) : rotationTime - Math.sqrt(ringData.getRingRotation());
138+
for(List<LaserWrapper> laserWrappers : lasers.values()) {
139+
for(LaserWrapper laserWrapper : laserWrappers) {
140+
laserWrapper.changeColor();
141+
}
142+
}
109143
}
110144

111145
public void ringZoom() {
112146
isZoomed = !isZoomed;
113-
zoomTime = isZoomed ? 1 : 0;
114147
}
115148
}

Core/src/main/java/exposed/hydrogen/nightclub/light/data/RingData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
@Builder
1818
public class RingData implements Cloneable{
1919
private RingMovementData ringMovementData;
20-
private String linkedRingUUID;
2120
private int ringCount;
21+
private int ringLightCount;
2222
private double ringSize;
2323
private double ringOffset;
2424
private double ringSpacing;
2525
private double ringRotation;
2626

2727
public RingData() {
28-
this(new RingMovementData(),"",0,0,0,0,0);
28+
this(new RingMovementData(),0,0,0,0,0,0);
2929
}
3030

3131
/**
@@ -35,7 +35,7 @@ public RingData() {
3535
* @param rotation The rotation of the ring
3636
* @return A list of the edge points of the ring
3737
*/
38-
public List<Vector3D> calculateRingEdgePoints(Vector3D center, double rotation) {
38+
public static List<Vector3D> calculateRingEdgePoints(Vector3D center, double rotation, int ringCount, double ringSize) {
3939
List<Vector3D> ringEdgePoints = new LinkedList<>();
4040
for (int i = 0; i < ringCount; i++) {
4141
Vector2D ringEdgePoint = LightPattern.CIRCLE.getPattern().apply(i*(100.0/ringCount)).scalarMultiply(ringSize);

Core/src/main/java/exposed/hydrogen/nightclub/util/Location.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public Location(Number x, Number y, Number z, Number pitch, Number yaw) {
2828
this.x = x.doubleValue();
2929
this.y = y.doubleValue();
3030
this.z = z.doubleValue();
31-
this.pitch = pitch.doubleValue() % 90;
31+
this.pitch = pitch.doubleValue();
3232
this.yaw = yaw.doubleValue() % 360;
3333
}
3434

Minestom/src/main/java/exposed/hydrogen/nightclub/MinestomUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public List<CrossCompatPlayer> getListOfPlayers() {
3535

3636
public static Location getNightclubLocation(Pos pos) {
3737
return new Location(pos.x(), pos.y(), pos.z(),
38-
-pos.pitch(), pos.yaw() + 270);
38+
-pos.pitch(), pos.yaw() - 270);
3939
}
4040

4141
public static Pos getMinestomPos(exposed.hydrogen.nightclub.util.Location location) {

Minestom/src/main/java/exposed/hydrogen/nightclub/NightclubMinestom.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import lombok.Getter;
99
import lombok.Setter;
1010
import net.minestom.server.MinecraftServer;
11+
import net.minestom.server.entity.GameMode;
12+
import net.minestom.server.event.player.PlayerLoginEvent;
1113
import net.minestom.server.extensions.Extension;
1214
import net.minestom.server.instance.Instance;
1315
import net.minestom.server.network.packet.server.play.TeamsPacket;
16+
import net.minestom.server.permission.Permission;
1417
import net.minestom.server.scoreboard.Team;
1518
import net.minestom.server.scoreboard.TeamBuilder;
1619

@@ -28,6 +31,16 @@ public LoadStatus initialize() {
2831
.collisionRule(TeamsPacket.CollisionRule.PUSH_OTHER_TEAMS)
2932
.build();
3033

34+
MinecraftServer.getGlobalEventHandler().addListener(PlayerLoginEvent.class, event -> {
35+
event.getPlayer().addPermission(new Permission("nightclub.light"));
36+
event.getPlayer().addPermission(new Permission("nightclub.lightuniverse"));
37+
event.getPlayer().addPermission(new Permission("nightclub.beatmap"));
38+
event.getPlayer().addPermission(new Permission("nightclub.ring"));
39+
event.getPlayer().setGameMode(GameMode.CREATIVE);
40+
event.getPlayer().setTeam(noCollisionTeam);
41+
chameleon.getLogger().info("added permissions for " + event.getPlayer());
42+
mapInstance.setTime(16000);
43+
});
3144
instance = this;
3245
util = new MinestomUtil();
3346
Nightclub.setCrossCompatUtil(util);
@@ -50,6 +63,7 @@ public LoadStatus initialize() {
5063

5164
@Override
5265
public void terminate() {
66+
Nightclub.getLightUniverseManager().save();
5367
chameleon.onDisable();
5468
}
5569
}

0 commit comments

Comments
 (0)