Skip to content

Commit 3fc6824

Browse files
First work on dynamic queues
1 parent 76a2169 commit 3fc6824

12 files changed

Lines changed: 114 additions & 124 deletions

src/main/java/net/pistonmaster/pistonqueue/bungee/commands/BungeeComponentWrapperImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/shared/CommandSourceWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/shared/ComponentWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/shared/ComponentWrapperFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/shared/PistonQueuePlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.concurrent.TimeUnit;
3838
import java.util.concurrent.atomic.AtomicBoolean;
3939
import java.util.concurrent.atomic.AtomicInteger;
40-
import java.util.concurrent.atomic.AtomicReference;
4140
import java.util.stream.Collectors;
4241

4342
public interface PistonQueuePlugin {
@@ -221,7 +220,7 @@ default void initializeReservationSlots() {
221220
if (!mainServer.isPresent())
222221
return;
223222

224-
Map<QueueType, AtomicInteger> map = new EnumMap<>(QueueType.class);
223+
Map<QueueType, AtomicInteger> map = new HashMap<>();
225224

226225
for (PlayerWrapper player : mainServer.get().getConnectedPlayers()) {
227226
QueueType playerType = QueueType.getQueueType(player::hasPermission);

src/main/java/net/pistonmaster/pistonqueue/shared/QueueListenerShared.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,8 @@ protected int getFreeSlots(QueueType type) {
178178
return type.getReservedSlots() - type.getPlayersWithTypeInMain().get();
179179
}
180180

181-
protected boolean isSlotsFull(int slots) {
182-
return slots <= 0;
183-
}
184-
185181
protected boolean isMainFull(QueueType type) {
186-
return isSlotsFull(getFreeSlots(type));
182+
return getFreeSlots(type) <= 0;
187183
}
188184

189185
protected boolean isAnyoneQueuedOfType(PlayerWrapper player) {
@@ -242,33 +238,34 @@ protected void doRecovery(PlayerWrapper player) {
242238
protected void connectPlayer(QueueType type) {
243239
int freeSlots = getFreeSlots(type);
244240

245-
if (isSlotsFull(freeSlots))
241+
if (freeSlots <= 0)
246242
return;
247243

248244
if (freeSlots > Config.MAX_PLAYERS_PER_MOVE)
249245
freeSlots = Config.MAX_PLAYERS_PER_MOVE;
250246

251247
for (Map.Entry<UUID, String> entry : new LinkedHashMap<>(type.getQueueMap()).entrySet()) {
252-
if (isSlotsFull(freeSlots))
248+
if (freeSlots <= 0)
253249
break;
254250

255-
Optional<PlayerWrapper> player = plugin.getPlayer(entry.getKey());
256-
if (!player.isPresent()) {
251+
Optional<PlayerWrapper> optional = plugin.getPlayer(entry.getKey());
252+
if (!optional.isPresent()) {
257253
continue;
258254
}
255+
PlayerWrapper player = optional.get();
259256

260257
freeSlots--;
261258

262259
type.getQueueMap().remove(entry.getKey());
263260

264-
player.get().sendMessage(Config.JOINING_MAIN_SERVER);
265-
player.get().sendPlayerListHeaderAndFooter(null, null);
261+
player.sendMessage(Config.JOINING_MAIN_SERVER);
262+
player.sendPlayerListHeaderAndFooter(null, null);
266263

267-
if (StorageTool.isShadowBanned(player.get().getUniqueId())
264+
if (StorageTool.isShadowBanned(player.getUniqueId())
268265
&& (Config.SHADOW_BAN_TYPE == BanType.LOOP
269266
|| (Config.SHADOW_BAN_TYPE == BanType.TEN_PERCENT && ThreadLocalRandom.current().nextInt(100) >= 10)
270267
|| (Config.SHADOW_BAN_TYPE == BanType.CUSTOM_PERCENT && ThreadLocalRandom.current().nextInt(100) >= Config.CUSTOM_PERCENT_PERCENTAGE))) {
271-
player.get().sendMessage(Config.SHADOW_BAN_MESSAGE);
268+
player.sendMessage(Config.SHADOW_BAN_MESSAGE);
272269

273270
type.getQueueMap().put(entry.getKey(), entry.getValue());
274271

@@ -283,8 +280,9 @@ protected void connectPlayer(QueueType type) {
283280
type.getDurationToPosition().put(position, Duration.between(instant, Instant.now())));
284281
}
285282

286-
player.get().connect(entry.getValue());
283+
player.connect(entry.getValue());
287284
}
285+
288286
if (Config.SEND_XP_SOUND)
289287
sendXPSoundToQueueType(type);
290288
}

src/main/java/net/pistonmaster/pistonqueue/shared/QueueType.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package net.pistonmaster.pistonqueue.shared;
2121

2222
import lombok.Getter;
23-
import net.pistonmaster.pistonqueue.shared.utils.Pair;
2423

2524
import java.time.Duration;
2625
import java.time.Instant;
@@ -29,23 +28,23 @@
2928
import java.util.concurrent.atomic.AtomicInteger;
3029
import java.util.function.Predicate;
3130

32-
public enum QueueType {
33-
REGULAR,
34-
PRIORITY,
35-
VETERAN;
36-
31+
public class QueueType {
32+
public static final QueueType REGULAR = new QueueType();
33+
public static final QueueType PRIORITY = new QueueType();
34+
public static final QueueType VETERAN = new QueueType();
3735
@Getter
3836
private final Map<UUID, String> queueMap = Collections.synchronizedMap(new LinkedHashMap<>());
39-
4037
@Getter
4138
private final Map<Integer, Duration> durationToPosition = Collections.synchronizedMap(new LinkedHashMap<>());
42-
4339
@Getter
4440
private final Map<UUID, Map<Integer, Instant>> positionCache = new ConcurrentHashMap<>();
45-
4641
@Getter
4742
private final AtomicInteger playersWithTypeInMain = new AtomicInteger();
4843

44+
public static QueueType[] values() {
45+
return new QueueType[]{REGULAR, PRIORITY, VETERAN};
46+
}
47+
4948
public static QueueType getQueueType(Predicate<String> player) {
5049
if (player.test(Config.QUEUE_VETERAN_PERMISSION)) {
5150
return VETERAN;
@@ -57,35 +56,29 @@ public static QueueType getQueueType(Predicate<String> player) {
5756
}
5857

5958
public List<String> getHeader() {
60-
switch (this) {
61-
case VETERAN:
62-
return Config.HEADER_VETERAN;
63-
case PRIORITY:
64-
return Config.HEADER_PRIORITY;
65-
default:
66-
return Config.HEADER;
59+
if (VETERAN.equals(this)) {
60+
return Config.HEADER_VETERAN;
61+
} else if (PRIORITY.equals(this)) {
62+
return Config.HEADER_PRIORITY;
6763
}
64+
return Config.HEADER;
6865
}
6966

7067
public List<String> getFooter() {
71-
switch (this) {
72-
case VETERAN:
73-
return Config.FOOTER_VETERAN;
74-
case PRIORITY:
75-
return Config.FOOTER_PRIORITY;
76-
default:
77-
return Config.FOOTER;
68+
if (VETERAN.equals(this)) {
69+
return Config.FOOTER_VETERAN;
70+
} else if (PRIORITY.equals(this)) {
71+
return Config.FOOTER_PRIORITY;
7872
}
73+
return Config.FOOTER;
7974
}
8075

8176
public int getReservedSlots() {
82-
switch (this) {
83-
case VETERAN:
84-
return Config.VETERAN_SLOTS;
85-
case PRIORITY:
86-
return Config.PRIORITY_SLOTS;
87-
default:
88-
return Config.REGULAR_SLOTS;
77+
if (VETERAN.equals(this)) {
78+
return Config.VETERAN_SLOTS;
79+
} else if (PRIORITY.equals(this)) {
80+
return Config.PRIORITY_SLOTS;
8981
}
82+
return Config.REGULAR_SLOTS;
9083
}
9184
}

src/main/java/net/pistonmaster/pistonqueue/shared/TextColorWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/shared/TextDecorationWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

src/main/java/net/pistonmaster/pistonqueue/velocity/PistonQueueVelocity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import net.pistonmaster.pistonqueue.shared.utils.MessageType;
4141
import net.pistonmaster.pistonqueue.shared.utils.UpdateChecker;
4242
import net.pistonmaster.pistonqueue.velocity.commands.MainCommand;
43-
import net.pistonmaster.pistonqueue.velocity.listeners.RegexListener;
4443
import net.pistonmaster.pistonqueue.velocity.listeners.QueueListenerVelocity;
44+
import net.pistonmaster.pistonqueue.velocity.listeners.RegexListener;
4545
import net.pistonmaster.pistonqueue.velocity.utils.ChatUtils;
4646
import org.bstats.velocity.Metrics;
4747
import org.slf4j.Logger;

0 commit comments

Comments
 (0)