Skip to content

Commit

Permalink
feat: ported new 0.2.32 features
Browse files Browse the repository at this point in the history
cf18063 - feat: new placeholders %bedwars_all_games_players% and %bedwars_all_games_maxplayers%
59b6104 - feat: allow configuring currency-changer which returns more items than the player sells
  • Loading branch information
Misat11 committed Feb 24, 2024
1 parent 5bd156c commit e5379b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,23 @@ private void handleBuy(OnTradeEvent event) {
return;
}

var split = changeItemToName.trim().split(" ", 2);
if (split.length == 2) {
try {
amount = Integer.parseInt(split[0]);
changeItemToName = split[1].trim();
if (changeItemToName.startsWith("of ")) {
changeItemToName = changeItemToName.substring(3).trim();
}
} catch (NumberFormatException ignored) {
}
}
var changeItemType = game.getGameVariant().getItemSpawnerType(changeItemToName);
if (changeItemType == null) {
return;
}

newItem = changeItemType.getItem();
newItem = changeItemType.getItem(amount);
}

var originalMaxStackSize = newItem.getMaterial().maxStackSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.screamingsandals.lib.spectator.Component;
import org.screamingsandals.lib.utils.annotations.Service;

import java.util.Locale;

@Service
public class BedwarsExpansion extends PlaceholderExpansion {

Expand Down Expand Up @@ -81,6 +83,16 @@ public Component onRequest(@Nullable MultiPlatformOfflinePlayer player, @NotNull
}
}

if (identifier.startsWith("all_games_")) {
var operation = identifier.substring(10).toLowerCase(Locale.ROOT);
switch (operation) {
case "players":
return Component.text(GameManagerImpl.getInstance().getGames().stream().mapToInt(GameImpl::countConnectedPlayers).sum());
case "maxplayers":
return Component.text(GameManagerImpl.getInstance().getGames().stream().mapToInt(GameImpl::getMaxPlayers).sum());
}
}

// other player stats

if (identifier.startsWith("otherstats_")) {
Expand Down

0 comments on commit e5379b6

Please sign in to comment.