Skip to content

Commit

Permalink
feat: (not tested) ported features and fixes from 0.2.32 and 0.2.32.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Misat11 committed May 13, 2024
1 parent a2b3efe commit 21d2220
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.Plugin;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.config.MainConfig;
import org.screamingsandals.bedwars.game.GameImpl;
import org.screamingsandals.bedwars.game.GameManagerImpl;
Expand Down Expand Up @@ -51,12 +52,24 @@ public void onServerListPing(ServerListPingEvent slpe) {
return;
}

GameImpl game = games.get(0);
Game gameA = null;
if (GameManagerImpl.getInstance().isDoGamePreselection()) {
gameA = GameManagerImpl.getInstance().getPreselectedGame();
}
if (gameA == null) {
if (MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()) {
gameA = GameManagerImpl.getInstance().getGameWithHighestPlayers().orElse(null);
} else {
gameA = games.get(0);
}
}

if (game == null) {
if (!(gameA instanceof GameImpl)) {
return;
}

var game = (GameImpl) gameA;

String string = null;

switch (game.getStatus()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public void load() {
.key("server").defValue("hub")
.key("auto-game-connect").defValue(false)
.key("kick-when-proxy-too-slow").defValue(true)
.key("select-random-game").defValue(true)
.section("random-game-selection")
.key("enabled").migrateOldAbsoluteKey("bungee", "select-random-game").defValue(true)
.key("preselect-games").defValue(true)
.back()
.section("motd")
.key("enabled").defValue(false)
.key("waiting").defValue("%name%: Waiting for players [%current%/%max%]")
Expand Down Expand Up @@ -341,6 +344,7 @@ public void load() {
.key("items-on-row").defValue(LocalOptions.ITEMS_ON_ROW)
.key("show-page-numbers").defValue(LocalOptions.SHOW_PAGE_NUMBER)
.key("inventory-type").defValue(LocalOptions.INVENTORY_TYPE)
.key("allow-execution-of-console-commands").defValue(true)
.back()
.section("items")
.key("jointeam").defValue("COMPASS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void initialize() {
driverClassName = reader.readLine();
if (driverClassName != null) {
// All characters after '#' should be ignored, whitespaces around the qualified name are also ignored
driverClassName = driver.split("#", 2)[0].trim();
driverClassName = driverClassName.split("#", 2)[0].trim();
}
} while (driverClassName != null && driverClassName.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,8 @@ public void run() {
}

if (isBungeeEnabled()) {
GameManagerImpl.getInstance().reselectGame();

preServerRestart = true;

if (!getConnectedPlayers().isEmpty()) {
Expand All @@ -2226,6 +2228,8 @@ public void run() {
Server.getConsoleSender().tryToDispatchCommand("restart");
} else if (MainConfig.getInstance().node("bungee", "serverStop").getBoolean()) {
Server.shutdown();
} else {
preServerRestart = false;
}
}, 30, TaskerTime.TICKS);
}
Expand All @@ -2248,7 +2252,7 @@ public void rebuild() {
});
otherVisuals.clear();
Debug.info(name + ": rebuilding starts");
teamsInGame.forEach(TeamImpl::destroy);
teams.forEach(TeamImpl::destroy); // Not destroyed teams may not be in teamsInGame
teamsInGame.clear();
activeSpecialItems.clear();
activeDelays.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

package org.screamingsandals.bedwars.game;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.GameManager;
import org.screamingsandals.bedwars.config.MainConfig;
import org.screamingsandals.bedwars.utils.MiscUtils;
import org.screamingsandals.bedwars.variants.VariantManagerImpl;
import org.screamingsandals.lib.plugin.ServiceManager;
import org.screamingsandals.lib.tasker.DefaultThreads;
import org.screamingsandals.lib.tasker.Tasker;
import org.screamingsandals.lib.utils.annotations.Service;
import org.screamingsandals.lib.utils.annotations.ServiceDependencies;
import org.screamingsandals.lib.utils.annotations.methods.OnPostEnable;
Expand All @@ -49,6 +55,11 @@ public class GameManagerImpl implements GameManager {
private final LoggerWrapper logger;
private final List<GameImpl> games = new LinkedList<>();

@Getter
private @Nullable Game preselectedGame;
@Getter
private boolean doGamePreselection;

public static GameManagerImpl getInstance() {
return ServiceManager.get(GameManagerImpl.class);
}
Expand Down Expand Up @@ -141,14 +152,33 @@ public void onPostEnable() {
e.printStackTrace();
}
}

if (
MainConfig.getInstance().node("bungee", "enabled").getBoolean()
&& MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()
&& MainConfig.getInstance().node("bungee", "random-game-selection", "preselect-games").getBoolean()
) {
Tasker.run(DefaultThreads.GLOBAL_THREAD, () -> {
preselectedGame = getGameWithHighestPlayers().orElse(null);
doGamePreselection = true;
});
}
}

@OnPreDisable
public void onPreDisable() {
preselectedGame = null;
doGamePreselection = false;
games.forEach(GameImpl::stop);
games.clear();
}

public void reselectGame() {
if (doGamePreselection) {
preselectedGame = getGameWithHighestPlayers().orElse(null);
}
}

@Override
public Optional<GameImpl> getGameWithHighestPlayers() {
return getGameWithHighestPlayers(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ private void loadNewShop(String name, File file) {
.genericShop(true)
.genericShopPriceTypeRequired(true)
.animationsEnabled(true)
.allowAccessToConsole(MainConfig.getInstance().node("shop", "allow-execution-of-console-commands").getBoolean())
.categoryOptions(localOptionsBuilder ->
localOptionsBuilder
.backItem(mainConfig.readDefinedItem("shopback", "BARRIER"), itemBuilder ->
Expand Down Expand Up @@ -468,7 +469,7 @@ private void handleBuy(OnTradeEvent event) {
}

var originalMaxStackSize = newItem.getMaterial().maxStackSize();
if (clickType.isShiftClick() && originalMaxStackSize > 1) {
if (!event.isHasAnyExecutions() && clickType.isShiftClick() && originalMaxStackSize > 1) {
double priceOfOne = (double) priceAmount / amount;
double maxStackSize;
int finalStackSize;
Expand Down Expand Up @@ -528,9 +529,13 @@ else if (propertyData.get(PermaItemListener.getPermItemPropKey()) != null) {
}

event.sellStack(materialItem);
var notFit = event.buyStack(newItem);
if (!notFit.isEmpty()) {
notFit.forEach(stack -> Entities.dropItem(stack, player.getLocation()));
if (event.isHasAnyExecutions()) {
event.setRunExecutions(true); // SIv2 will handle that when this is set to true
} else {
var notFit = event.buyStack(newItem);
if (!notFit.isEmpty()) {
notFit.forEach(stack -> Entities.dropItem(stack, player.getLocation()));
}
}

if (!mainConfig.node("removePurchaseMessages").getBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.screamingsandals.bedwars.PlatformService;
import org.screamingsandals.bedwars.api.config.GameConfigurationContainer;
import org.screamingsandals.bedwars.api.events.TargetInvalidationReason;
import org.screamingsandals.bedwars.api.game.Game;
import org.screamingsandals.bedwars.api.game.GameStatus;
import org.screamingsandals.bedwars.commands.BedWarsPermission;
import org.screamingsandals.bedwars.commands.admin.JoinTeamCommand;
Expand Down Expand Up @@ -343,21 +344,29 @@ public void onPlayerJoin(PlayerJoinEvent event) {
try {
Debug.info("Selecting game for " + event.player().getName());
var gameManager = GameManagerImpl.getInstance();
var game = (
MainConfig.getInstance().node("bungee", "select-random-game").getBoolean()
? gameManager.getGameWithHighestPlayers()
: gameManager.getFirstWaitingGame()
).or(gameManager::getFirstRunningGame);
if (game.isEmpty()) { // still nothing?
Game game = null;
if (MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()) {
if (gameManager.isDoGamePreselection()) {
game = gameManager.getPreselectedGame();
}
}
if (game == null) {
game = (
MainConfig.getInstance().node("bungee", "random-game-selection", "enabled").getBoolean()
? gameManager.getGameWithHighestPlayers()
: gameManager.getFirstWaitingGame()
).or(gameManager::getFirstRunningGame).orElse(null);
}
if (game == null) { // still nothing?
if (!player.hasPermission(BedWarsPermission.ADMIN_PERMISSION.asPermission())) {
Debug.info(event.player().getName() + " is not connecting to any game! Kicking...");
BungeeUtils.movePlayerToBungeeServer(player, false);
}
return;
}
Debug.info(event.player().getName() + " is connecting to " + game.get().getName());
Debug.info(event.player().getName() + " is connecting to " + game.getName());

game.get().joinToGame(PlayerManagerImpl.getInstance().getPlayerOrCreate(player));
game.joinToGame(PlayerManagerImpl.getInstance().getPlayerOrCreate(player));
} catch (NullPointerException ignored) {
if (!player.hasPermission(BedWarsPermission.ADMIN_PERMISSION.asPermission())) {
Debug.info(event.player().getName() + " is not connecting to any game! Kicking...");
Expand Down
Loading

0 comments on commit 21d2220

Please sign in to comment.