Skip to content

Commit 21d2220

Browse files
committed
feat: (not tested) ported features and fixes from 0.2.32 and 0.2.32.1
Ported commits: e9c6a7b fix: fixed custom driver class loading e754068 feat: new placeholders 5aa2dbb feat: new placeholders 0a52cb1 feat: game preselection (bungee.random-game-selection.preselect-games), fixed wrong game in motd 53b035c feat: command executions in shop behind "paywall" + console executions
1 parent a2b3efe commit 21d2220

File tree

8 files changed

+291
-27
lines changed

8 files changed

+291
-27
lines changed

plugin/bukkit/src/main/java/org/screamingsandals/bedwars/bukkit/listener/BungeeMotdListener.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.bukkit.event.Listener;
2424
import org.bukkit.event.server.ServerListPingEvent;
2525
import org.bukkit.plugin.Plugin;
26+
import org.screamingsandals.bedwars.api.game.Game;
2627
import org.screamingsandals.bedwars.config.MainConfig;
2728
import org.screamingsandals.bedwars.game.GameImpl;
2829
import org.screamingsandals.bedwars.game.GameManagerImpl;
@@ -51,12 +52,24 @@ public void onServerListPing(ServerListPingEvent slpe) {
5152
return;
5253
}
5354

54-
GameImpl game = games.get(0);
55+
Game gameA = null;
56+
if (GameManagerImpl.getInstance().isDoGamePreselection()) {
57+
gameA = GameManagerImpl.getInstance().getPreselectedGame();
58+
}
59+
if (gameA == null) {
60+
if (MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()) {
61+
gameA = GameManagerImpl.getInstance().getGameWithHighestPlayers().orElse(null);
62+
} else {
63+
gameA = games.get(0);
64+
}
65+
}
5566

56-
if (game == null) {
67+
if (!(gameA instanceof GameImpl)) {
5768
return;
5869
}
5970

71+
var game = (GameImpl) gameA;
72+
6073
String string = null;
6174

6275
switch (game.getStatus()) {

plugin/common/src/main/java/org/screamingsandals/bedwars/config/MainConfig.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ public void load() {
183183
.key("server").defValue("hub")
184184
.key("auto-game-connect").defValue(false)
185185
.key("kick-when-proxy-too-slow").defValue(true)
186-
.key("select-random-game").defValue(true)
186+
.section("random-game-selection")
187+
.key("enabled").migrateOldAbsoluteKey("bungee", "select-random-game").defValue(true)
188+
.key("preselect-games").defValue(true)
189+
.back()
187190
.section("motd")
188191
.key("enabled").defValue(false)
189192
.key("waiting").defValue("%name%: Waiting for players [%current%/%max%]")
@@ -341,6 +344,7 @@ public void load() {
341344
.key("items-on-row").defValue(LocalOptions.ITEMS_ON_ROW)
342345
.key("show-page-numbers").defValue(LocalOptions.SHOW_PAGE_NUMBER)
343346
.key("inventory-type").defValue(LocalOptions.INVENTORY_TYPE)
347+
.key("allow-execution-of-console-commands").defValue(true)
344348
.back()
345349
.section("items")
346350
.key("jointeam").defValue("COMPASS")

plugin/common/src/main/java/org/screamingsandals/bedwars/database/DatabaseManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void initialize() {
101101
driverClassName = reader.readLine();
102102
if (driverClassName != null) {
103103
// All characters after '#' should be ignored, whitespaces around the qualified name are also ignored
104-
driverClassName = driver.split("#", 2)[0].trim();
104+
driverClassName = driverClassName.split("#", 2)[0].trim();
105105
}
106106
} while (driverClassName != null && driverClassName.isEmpty());
107107
}

plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,8 @@ public void run() {
22132213
}
22142214

22152215
if (isBungeeEnabled()) {
2216+
GameManagerImpl.getInstance().reselectGame();
2217+
22162218
preServerRestart = true;
22172219

22182220
if (!getConnectedPlayers().isEmpty()) {
@@ -2226,6 +2228,8 @@ public void run() {
22262228
Server.getConsoleSender().tryToDispatchCommand("restart");
22272229
} else if (MainConfig.getInstance().node("bungee", "serverStop").getBoolean()) {
22282230
Server.shutdown();
2231+
} else {
2232+
preServerRestart = false;
22292233
}
22302234
}, 30, TaskerTime.TICKS);
22312235
}
@@ -2248,7 +2252,7 @@ public void rebuild() {
22482252
});
22492253
otherVisuals.clear();
22502254
Debug.info(name + ": rebuilding starts");
2251-
teamsInGame.forEach(TeamImpl::destroy);
2255+
teams.forEach(TeamImpl::destroy); // Not destroyed teams may not be in teamsInGame
22522256
teamsInGame.clear();
22532257
activeSpecialItems.clear();
22542258
activeDelays.clear();

plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameManagerImpl.java

+30
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919

2020
package org.screamingsandals.bedwars.game;
2121

22+
import lombok.Getter;
2223
import lombok.RequiredArgsConstructor;
2324
import org.jetbrains.annotations.NotNull;
25+
import org.jetbrains.annotations.Nullable;
26+
import org.screamingsandals.bedwars.api.game.Game;
2427
import org.screamingsandals.bedwars.api.game.GameManager;
28+
import org.screamingsandals.bedwars.config.MainConfig;
2529
import org.screamingsandals.bedwars.utils.MiscUtils;
2630
import org.screamingsandals.bedwars.variants.VariantManagerImpl;
2731
import org.screamingsandals.lib.plugin.ServiceManager;
32+
import org.screamingsandals.lib.tasker.DefaultThreads;
33+
import org.screamingsandals.lib.tasker.Tasker;
2834
import org.screamingsandals.lib.utils.annotations.Service;
2935
import org.screamingsandals.lib.utils.annotations.ServiceDependencies;
3036
import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable;
@@ -49,6 +55,11 @@ public class GameManagerImpl implements GameManager {
4955
private final LoggerWrapper logger;
5056
private final List<GameImpl> games = new LinkedList<>();
5157

58+
@Getter
59+
private @Nullable Game preselectedGame;
60+
@Getter
61+
private boolean doGamePreselection;
62+
5263
public static GameManagerImpl getInstance() {
5364
return ServiceManager.get(GameManagerImpl.class);
5465
}
@@ -141,14 +152,33 @@ public void onPostEnable() {
141152
e.printStackTrace();
142153
}
143154
}
155+
156+
if (
157+
MainConfig.getInstance().node("bungee", "enabled").getBoolean()
158+
&& MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()
159+
&& MainConfig.getInstance().node("bungee", "random-game-selection", "preselect-games").getBoolean()
160+
) {
161+
Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> {
162+
preselectedGame = getGameWithHighestPlayers().orElse(null);
163+
doGamePreselection = true;
164+
});
165+
}
144166
}
145167

146168
@OnPreDisable
147169
public void onPreDisable() {
170+
preselectedGame = null;
171+
doGamePreselection = false;
148172
games.forEach(GameImpl::stop);
149173
games.clear();
150174
}
151175

176+
public void reselectGame() {
177+
if (doGamePreselection) {
178+
preselectedGame = getGameWithHighestPlayers().orElse(null);
179+
}
180+
}
181+
152182
@Override
153183
public Optional<GameImpl> getGameWithHighestPlayers() {
154184
return getGameWithHighestPlayers(false);

plugin/common/src/main/java/org/screamingsandals/bedwars/inventories/ShopInventory.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ private void loadNewShop(String name, File file) {
277277
.genericShop(true)
278278
.genericShopPriceTypeRequired(true)
279279
.animationsEnabled(true)
280+
.allowAccessToConsole(MainConfig.getInstance().node("shop", "allow-execution-of-console-commands").getBoolean())
280281
.categoryOptions(localOptionsBuilder ->
281282
localOptionsBuilder
282283
.backItem(mainConfig.readDefinedItem("shopback", "BARRIER"), itemBuilder ->
@@ -468,7 +469,7 @@ private void handleBuy(OnTradeEvent event) {
468469
}
469470

470471
var originalMaxStackSize = newItem.getMaterial().maxStackSize();
471-
if (clickType.isShiftClick() && originalMaxStackSize > 1) {
472+
if (!event.isHasAnyExecutions() && clickType.isShiftClick() && originalMaxStackSize > 1) {
472473
double priceOfOne = (double) priceAmount / amount;
473474
double maxStackSize;
474475
int finalStackSize;
@@ -528,9 +529,13 @@ else if (propertyData.get(PermaItemListener.getPermItemPropKey()) != null) {
528529
}
529530

530531
event.sellStack(materialItem);
531-
var notFit = event.buyStack(newItem);
532-
if (!notFit.isEmpty()) {
533-
notFit.forEach(stack -> Entities.dropItem(stack, player.getLocation()));
532+
if (event.isHasAnyExecutions()) {
533+
event.setRunExecutions(true); // SIv2 will handle that when this is set to true
534+
} else {
535+
var notFit = event.buyStack(newItem);
536+
if (!notFit.isEmpty()) {
537+
notFit.forEach(stack -> Entities.dropItem(stack, player.getLocation()));
538+
}
534539
}
535540

536541
if (!mainConfig.node("removePurchaseMessages").getBoolean()) {

plugin/common/src/main/java/org/screamingsandals/bedwars/listener/PlayerListener.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.screamingsandals.bedwars.PlatformService;
2424
import org.screamingsandals.bedwars.api.config.GameConfigurationContainer;
2525
import org.screamingsandals.bedwars.api.events.TargetInvalidationReason;
26+
import org.screamingsandals.bedwars.api.game.Game;
2627
import org.screamingsandals.bedwars.api.game.GameStatus;
2728
import org.screamingsandals.bedwars.commands.BedWarsPermission;
2829
import org.screamingsandals.bedwars.commands.admin.JoinTeamCommand;
@@ -343,21 +344,29 @@ public void onPlayerJoin(PlayerJoinEvent event) {
343344
try {
344345
Debug.info("Selecting game for " + event.player().getName());
345346
var gameManager = GameManagerImpl.getInstance();
346-
var game = (
347-
MainConfig.getInstance().node("bungee", "select-random-game").getBoolean()
348-
? gameManager.getGameWithHighestPlayers()
349-
: gameManager.getFirstWaitingGame()
350-
).or(gameManager::getFirstRunningGame);
351-
if (game.isEmpty()) { // still nothing?
347+
Game game = null;
348+
if (MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()) {
349+
if (gameManager.isDoGamePreselection()) {
350+
game = gameManager.getPreselectedGame();
351+
}
352+
}
353+
if (game == null) {
354+
game = (
355+
MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()
356+
? gameManager.getGameWithHighestPlayers()
357+
: gameManager.getFirstWaitingGame()
358+
).or(gameManager::getFirstRunningGame).orElse(null);
359+
}
360+
if (game == null) { // still nothing?
352361
if (!player.hasPermission(BedWarsPermission.ADMIN_PERMISSION.asPermission())) {
353362
Debug.info(event.player().getName() + " is not connecting to any game! Kicking...");
354363
BungeeUtils.movePlayerToBungeeServer(player, false);
355364
}
356365
return;
357366
}
358-
Debug.info(event.player().getName() + " is connecting to " + game.get().getName());
367+
Debug.info(event.player().getName() + " is connecting to " + game.getName());
359368

360-
game.get().joinToGame(PlayerManagerImpl.getInstance().getPlayerOrCreate(player));
369+
game.joinToGame(PlayerManagerImpl.getInstance().getPlayerOrCreate(player));
361370
} catch (NullPointerException ignored) {
362371
if (!player.hasPermission(BedWarsPermission.ADMIN_PERMISSION.asPermission())) {
363372
Debug.info(event.player().getName() + " is not connecting to any game! Kicking...");

0 commit comments

Comments
 (0)