Skip to content

Commit

Permalink
feat: ported features and fixes from 0.2.30 & snapshots of 0.2.31
Browse files Browse the repository at this point in the history
Ported:
6fff1a3 feat: players-can-win-game-only-after-seconds option - Players cannot win the game, if the game is shorter than specified value
7043179 refactor: replaced Bukkit enchantment names with Mojang names in default shop files
f7c7278 refactor: updated to si 1.0.6.9, updated default shop files to use only lowercased mojang names
33b8883 go back to snapshot, updated takenaka, added #getStatistic method to API
7314ccf fix: force loading player's statistics on join

Partially ported:
062a3c0 fix: spawner desync in SBA and wrong total spawned items computation

Not ported yet:
41bd314 fix: attempt to fix empty spawners
cd98595 feat: /bw cheatIn command
  • Loading branch information
Misat11 committed Nov 4, 2023
1 parent 18ea15e commit 3e747f9
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 516 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public interface GameConfigurationContainer extends ConfigurationContainer {
ConfigurationKey<Boolean> DISABLE_CAKE_EATING = ConfigurationKey.of(Boolean.class, "disable-cake-eating");
ConfigurationKey<Boolean> DISABLE_FLIGHT = ConfigurationKey.of(Boolean.class, "disable-flight");
ConfigurationKey<Boolean> ALLOW_FAKE_DEATH = ConfigurationKey.of(Boolean.class, "allow-fake-death");
ConfigurationKey<Boolean> RESET_FULL_SPAWNER_COUNTDOWN_AFTER_PICKING = ConfigurationKey.of(Boolean.class, "reset-full-spawner-countdown-after-picking");
ConfigurationKey<Integer> PLAYERS_CAN_WIN_GAME_ONLY_AFTER_SECONDS = ConfigurationKey.of(Integer.class, "players-can-win-game-only-after-seconds");

ConfigurationKey<String> PREFIX = ConfigurationKey.of(String.class, "prefix");
ConfigurationKey<String> DEFAULT_SHOP_FILE = ConfigurationKey.of(String.class, "default-shop-file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
public interface PlayerStatisticsManager {

List<? extends LeaderboardEntry> getLeaderboard(int count);

PlayerStatistic getStatistic(UUID uuid);

/**
* @see #getStatistic(UUID)
*/
PlayerStatistic loadStatistic(UUID uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class GameConfigurationContainerImpl extends ConfigurationContainerImpl i
register(DISABLE_CAKE_EATING, "disable-cake-eating");
register(DISABLE_FLIGHT, "disable-flight");
register(ALLOW_FAKE_DEATH, "allow-fake-death");
register(RESET_FULL_SPAWNER_COUNTDOWN_AFTER_PICKING, "reset-full-spawner-countdown-after-picking");
register(PLAYERS_CAN_WIN_GAME_ONLY_AFTER_SECONDS, "players-can-win-game-only-after-seconds");
register(DEFAULT_SHOP_FILE);
register(PREFIX, "prefix");
register(ARENA_TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public void load() {
.key("prefer-1-19-4-display-entities").defValue(true)
.key("remember-what-scoreboards-players-had-before").defValue(false)
.key("use-chunk-tickets-if-available").defValue(true)
.key("reset-full-spawner-countdown-after-picking").defValue(true)
.key("players-can-win-game-only-after-seconds").defValue(0)
.section("kick-players-upon-final-death")
.key("enabled").defValue(false)
.key("delay").defValue(5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2069,86 +2069,92 @@ public void run() {
}
if (runningTeams <= 1) {
if (runningTeams == 1) {
TeamImpl winner = null;
for (var t : teamsInGame) {
if (t.isAlive()) {
winner = t;
String time = getFormattedTimeLeft(gameTime - countdown);
var message = Message
.of(LangKeys.IN_GAME_END_TEAM_WIN)
.prefixOrDefault(getCustomPrefixComponent())
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time);
boolean madeRecord = processRecord(t, gameTime - countdown);
for (BedWarsPlayer player : players) {
player.sendMessage(message);
if (getPlayerTeam(player) == t) {
Message.of(LangKeys.IN_GAME_END_YOU_WON)
.join(LangKeys.IN_GAME_END_TEAM_WIN)
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time)
.times(TitleUtils.defaultTimes())
.title(player);
EconomyUtils.deposit(player, configurationContainer.getOrDefault(GameConfigurationContainer.ECONOMY_REWARD_WIN, 0.0));

SpawnEffects.spawnEffect(this, player, "game-effects.end");

if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance()
.getStatistic(player);
statistic.addWins(1);
statistic.addScore(configurationContainer.getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_WIN, 50));

if (madeRecord) {
statistic.addScore(configurationContainer.getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_RECORD, 100));
}
if (gameTime - countdown < configurationContainer.getOrDefault(GameConfigurationContainer.PLAYERS_CAN_WIN_GAME_ONLY_AFTER_SECONDS, 0)) {
Message.of(LangKeys.IN_GAME_END_YOU_LOST)
.join(LangKeys.IN_GAME_END_GAME_ENDED_TOO_EARLY)
.title(players);
} else {
TeamImpl winner = null;
for (var t : teamsInGame) {
if (t.isAlive()) {
winner = t;
String time = getFormattedTimeLeft(gameTime - countdown);
var message = Message
.of(LangKeys.IN_GAME_END_TEAM_WIN)
.prefixOrDefault(getCustomPrefixComponent())
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time);
boolean madeRecord = processRecord(t, gameTime - countdown);
for (BedWarsPlayer player : players) {
player.sendMessage(message);
if (getPlayerTeam(player) == t) {
Message.of(LangKeys.IN_GAME_END_YOU_WON)
.join(LangKeys.IN_GAME_END_TEAM_WIN)
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time)
.times(TitleUtils.defaultTimes())
.title(player);
EconomyUtils.deposit(player, configurationContainer.getOrDefault(GameConfigurationContainer.ECONOMY_REWARD_WIN, 0.0));

SpawnEffects.spawnEffect(this, player, "game-effects.end");

if (StatisticsHolograms.isEnabled()) {
StatisticsHolograms.getInstance().updateHolograms(player);
}
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance()
.getStatistic(player);
statistic.addWins(1);
statistic.addScore(configurationContainer.getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_WIN, 50));

if (MainConfig.getInstance().node("statistics", "show-on-game-end")
.getBoolean()) {
StatsCommand.sendStats(player, PlayerStatisticManager.getInstance().getStatistic(player));
}
if (madeRecord) {
statistic.addScore(configurationContainer.getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_RECORD, 100));
}

}
if (StatisticsHolograms.isEnabled()) {
StatisticsHolograms.getInstance().updateHolograms(player);
}

if (MainConfig.getInstance().node("statistics", "show-on-game-end")
.getBoolean()) {
StatsCommand.sendStats(player, PlayerStatisticManager.getInstance().getStatistic(player));
}

if (MainConfig.getInstance().node("rewards", "enabled").getBoolean()) {
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance().getStatistic(player);
GameImpl.this.dispatchRewardCommands("player-win-run-immediately", player, statistic.getScore());
} else {
GameImpl.this.dispatchRewardCommands("player-win-run-immediately", player, 0);
}
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {

if (MainConfig.getInstance().node("rewards", "enabled").getBoolean()) {
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance().getStatistic(player);
GameImpl.this.dispatchRewardCommands("player-win", player, statistic.getScore());
GameImpl.this.dispatchRewardCommands("player-win-run-immediately", player, statistic.getScore());
} else {
GameImpl.this.dispatchRewardCommands("player-win", player, 0);
GameImpl.this.dispatchRewardCommands("player-win-run-immediately", player, 0);
}
}, (2 + postGameWaiting) * 20L, TaskerTime.TICKS);
}
} else {
Message.of(LangKeys.IN_GAME_END_YOU_LOST)
.join(LangKeys.IN_GAME_END_TEAM_WIN)
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time)
.times(TitleUtils.defaultTimes())
.title(player);

if (StatisticsHolograms.isEnabled()) {
StatisticsHolograms.getInstance().updateHolograms(player);
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance().getStatistic(player);
GameImpl.this.dispatchRewardCommands("player-win", player, statistic.getScore());
} else {
GameImpl.this.dispatchRewardCommands("player-win", player, 0);
}
}, (2 + postGameWaiting) * 20L, TaskerTime.TICKS);
}
} else {
Message.of(LangKeys.IN_GAME_END_YOU_LOST)
.join(LangKeys.IN_GAME_END_TEAM_WIN)
.placeholder("team", Component.text(t.getName(), t.getColor().getTextColor()))
.placeholder("time", time)
.times(TitleUtils.defaultTimes())
.title(player);

if (StatisticsHolograms.isEnabled()) {
StatisticsHolograms.getInstance().updateHolograms(player);
}
}
}
break;
}
break;
}
}

var endingEvent = new GameEndingEventImpl(this, winner);
EventManager.fire(endingEvent);
var endingEvent = new GameEndingEventImpl(this, winner);
EventManager.fire(endingEvent);
}
EventManager.fire(statusE);
Debug.info(name + ": game is ending");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public int nextMaxSpawn(int calculated) {
/* Update spawned items */
spawnedItems.removeIf(Entity::isDead);

int spawned = spawnedItems.size();
int spawned = getSpawnedItemsCount();

if (spawned >= maxSpawnedResources) {
if (hologram != null && !spawnerIsFullHologram) {
Expand Down Expand Up @@ -194,13 +194,20 @@ public void add(ItemEntity item) {
public void remove(ItemEntity item) {
if (maxSpawnedResources > 0 && spawnedItems.contains(item)) {
spawnedItems.remove(item);
if (spawnerIsFullHologram && maxSpawnedResources > spawnedItems.size()) {
if (spawnerIsFullHologram && maxSpawnedResources > getSpawnedItemsCount()) {
spawnerIsFullHologram = false;
rerenderHologram = true;
}
}
}

/**
* Works only if maxSpawnedResources > 0
*/
public int getSpawnedItemsCount() {
return spawnedItems.stream().mapToInt(i -> i.getItem().getAmount()).sum();
}

@Override
@Tolerate
public void setItemSpawnerType(ItemSpawnerType spawnerType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class LangKeys {
public final String[] IN_GAME_BOSSBAR_RUNNING = {"in_game", "bossbar", "running"};
public final String[] IN_GAME_END_YOU_WON = {"in_game", "end", "you_won"};
public final String[] IN_GAME_END_YOU_LOST = {"in_game", "end", "you_lost"};
public final String[] IN_GAME_END_GAME_ENDED_TOO_EARLY = {"in_game", "end", "game_ended_too_early"};
public final String[] IN_GAME_END_TEAM_WIN = {"in_game", "end", "team_win"};
public final String[] IN_GAME_END_GAME_END = {"in_game", "end", "game_end"};
public final String[] IN_GAME_RESPAWN_PROTECTION_REMAINING = {"in_game", "respawn_protection", "remaining"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ public void onPlayerJoin(PlayerJoinEvent event) {
if (MainConfig.getInstance().node("tab", "enabled").getBoolean() && MainConfig.getInstance().node("tab", "hide-foreign-players").getBoolean()) {
Server.getConnectedPlayers().stream().filter(PlayerManagerImpl.getInstance()::isPlayerInGame).forEach(p -> PlayerManagerImpl.getInstance().getPlayer(p).orElseThrow().hidePlayer(player));
}

if (PlayerStatisticManager.isEnabled()) {
PlayerStatisticManager.getInstance().loadStatistic(event.player().getUuid());
}
}

@OnEvent(order = EventExecutionOrder.LAST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Nullable;
import org.screamingsandals.bedwars.api.statistics.PlayerStatistic;
import org.screamingsandals.bedwars.api.statistics.PlayerStatisticsManager;
import org.screamingsandals.bedwars.config.MainConfig;
import org.screamingsandals.bedwars.database.DatabaseManager;
Expand Down Expand Up @@ -86,11 +87,21 @@ public PlayerStatisticImpl getStatistic(OfflinePlayer player) {
return null;
}

if (!this.playerStatistic.containsKey(player.getUuid())) {
return this.loadStatistic(player.getUuid());
return getStatistic(player.getUuid());
}


@Override
public PlayerStatisticImpl getStatistic(UUID uuid) {
if (uuid == null) {
return null;
}

if (!this.playerStatistic.containsKey(uuid)) {
return this.loadStatistic(uuid);
}

return this.playerStatistic.get(player.getUuid());
return this.playerStatistic.get(uuid);
}

@OnEnable
Expand Down Expand Up @@ -239,7 +250,7 @@ private PlayerStatisticImpl loadDatabaseStatistic(UUID uuid) {
}

this.playerStatistic.put(playerStatistic.getUuid(), playerStatistic);
this.allScores.put(uuid, new AbstractMap.SimpleEntry<>(playerStatistic.getName(), playerStatistic.getScore()));
updateScore(playerStatistic);
return playerStatistic;
}

Expand All @@ -264,7 +275,7 @@ private PlayerStatisticImpl loadYamlStatistic(UUID uuid) {
}

this.playerStatistic.put(uuid, playerStatistic);
this.allScores.put(uuid, new AbstractMap.SimpleEntry<>(playerStatistic.getName(), playerStatistic.getScore()));
updateScore(playerStatistic);
return playerStatistic;
}

Expand Down
Loading

0 comments on commit 3e747f9

Please sign in to comment.