Skip to content

Commit

Permalink
fix: port 0.2.34 fixes
Browse files Browse the repository at this point in the history
Ported:
- a2fb790 feat: go to snapshot, (not tested) new "reward" commands
- 69783ad fix: waterlogging a block does not revert the state upon rebuilding
- 35fd7d4 fix: spectator should not be able to teleport to players outside of the arena
- 65df090 fix: #542
- abc01f3 fix: filling bucket does not check for block breakability and does not register the blocks for rebuild
  • Loading branch information
Misat11 committed Aug 17, 2024
1 parent 84ee0bc commit 678a2bb
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Flexible BedWars plugin formerly coded as a replacement for BedwarsRel.

Supported versions: \[1.8.8 - 1.21\]. Recommended version: \[1.20.6\]
Supported versions: \[1.8.8 - 1.21.1\]. Recommended version: \[1.21.1\]

## Support
If you need any help, you can contact us on [Discord](https://discord.gg/4xB54Ts). Please make sure to look into older messages. There are many question already answered. It is really anoying to repeat the same thing over and over.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void regen() {
var feedState = bBlockFeed.getState();

headState.setType(brokenBlockTypes.get(blockHead));
feedState.setType(brokenBlockTypes.get(blockFeed));
feedState.setType(brokenBlockTypes.getOrDefault(blockFeed, brokenBlockTypes.get(blockHead)));
headState.setRawData((byte) 0x0);
feedState.setRawData((byte) 0x8);
feedState.update(true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ public void load() {
.key("player-destroy-bed").defValue(() -> List.of("/example {player} {score}"))
.key("player-kill").defValue(() -> List.of("/example {player} 10"))
.key("player-final-kill").defValue(() -> List.of("/example {player} 10"))
.key("player-game-start").defValue(() -> List.of("/example {player} 10"))
.key("player-early-leave").defValue(() -> List.of("/example {player} {death} 10"))
.key("team-win").defValue(() -> List.of("/example {team} 10"))
.key("player-team-win").defValue(() -> List.of("/example {team} {death} 10"))
.key("game-start").defValue(() -> List.of("/example Hello World!"))
.back()
.section("lore")
.key("generate-automatically").defValue(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.RequiredArgsConstructor;
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.GameCycle;
import org.screamingsandals.bedwars.api.game.GameStatus;
import org.screamingsandals.bedwars.boss.BossBarImpl;
Expand Down Expand Up @@ -221,6 +222,11 @@ private void tickRunningGame(GameChangedStatusEventImpl statusE, GameTickEventIm

var endingEvent = new GameEndingEventImpl(game, winner);
EventManager.fire(endingEvent);

game.dispatchRewardCommands("team-win", null, 0, winner, null, null);
for (var member : winner.getTeamMembers()) {
game.dispatchRewardCommands("player-team-win", null, 0, winner, winner.getPlayers().stream().anyMatch(p -> p.getUniqueId().equals(member.getUuid())), member);
}
}
EventManager.fire(statusE);
Debug.info(game.getName() + ": game is ending");
Expand Down Expand Up @@ -263,7 +269,7 @@ private void handlePlayerWin(BedWarsPlayer player, TeamImpl winner, String time,
}

if (MainConfig.getInstance().node("rewards", "enabled").getBoolean()) {
game.dispatchPlayerWinReward(player);
game.dispatchPlayerWinReward(player, winner);
}
}

Expand Down Expand Up @@ -422,6 +428,11 @@ private void prepareGame(GameChangedStatusEventImpl statusE, GameTickEventImpl t
if (configurationContainer.getOrDefault(GameConfigurationContainer.ENABLE_BELOW_NAME_HEALTH_INDICATOR, false)) {
game.startHealthIndicator();
}

for (var player : players) {
game.dispatchRewardCommands("player-game-start", player, 0, game.getPlayerTeam(player), null, null);
}
game.dispatchRewardCommands("game-start", null, 0);
}

// show records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ public void internalLeavePlayer(BedWarsPlayer gamePlayer) {
}
}
}

if (status == GameStatus.RUNNING) {
dispatchRewardCommands("player-early-leave", gamePlayer, 0, team, gamePlayer.isSpectator(), null);
}
}

if (PlayerStatisticManager.isEnabled()) {
Expand Down Expand Up @@ -1768,7 +1772,11 @@ public List<ItemSpawnerImpl> getItemSpawners() {
return List.copyOf(spawners);
}

public void dispatchRewardCommands(String type, Player player, int score) {
public void dispatchRewardCommands(@NotNull String type, @Nullable Player player, int score) {
dispatchRewardCommands(type, player, score, null, null, null);
}

public void dispatchRewardCommands(@NotNull String type, @Nullable Player player, int score, @Nullable TeamImpl team, @Nullable Boolean deathStatus, TeamImpl.@Nullable Member member) {
if (!MainConfig.getInstance().node("rewards", "enabled").getBoolean()) {
return;
}
Expand All @@ -1777,12 +1785,33 @@ public void dispatchRewardCommands(String type, Player player, int score) {
.stream()
.map(ConfigurationNode::getString)
.filter(Objects::nonNull)
.map(s -> s
.replace("{player}", player.getName())
.replace("{score}", Integer.toString(score))
)
.map(command -> {
if (command.startsWith("/example ")) {
return null; // Skip example commands
}

if (player != null) {
command = command.replace("{player}", player.getName());
command = command.replace("{playerUuid}", player.getUniqueId().toString());
}
if (member != null) {
command = command.replace("{player}", member.getName());
command = command.replace("{playerUuid}", member.getUuid().toString());
}
command = command.replace("{game}", name);
command = command.replace("{score}", Integer.toString(score));
if (team != null) {
command = command.replace("{team}", team.getName());
}
if (deathStatus != null) {
command = command.replace("{death}", deathStatus ? "true" : "false");
}

return command;
})
.filter(Objects::nonNull)
.map(s -> s.startsWith("/") ? s.substring(1) : s)
.forEach(player::tryToDispatchCommand);
.forEach(Server.getConsoleSender()::tryToDispatchCommand);
}

@Override
Expand Down Expand Up @@ -2009,19 +2038,19 @@ public void showPlayerCountdown(int countdown) {
}
}

protected void dispatchPlayerWinReward(Player player) {
protected void dispatchPlayerWinReward(@NotNull Player player, @NotNull TeamImpl winningTeam) {
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance().getStatistic(player);
dispatchRewardCommands("player-win-run-immediately", player, statistic.getScore());
dispatchRewardCommands("player-win-run-immediately", player, statistic.getScore(), winningTeam, null, null);
} else {
dispatchRewardCommands("player-win-run-immediately", player, 0);
dispatchRewardCommands("player-win-run-immediately", player, 0, winningTeam, null, null);
}
Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, () -> {
if (PlayerStatisticManager.isEnabled()) {
var statistic = PlayerStatisticManager.getInstance().getStatistic(player);
dispatchRewardCommands("player-win", player, statistic.getScore());
dispatchRewardCommands("player-win", player, statistic.getScore(), winningTeam, null, null);
} else {
dispatchRewardCommands("player-win", player, 0);
dispatchRewardCommands("player-win", player, 0, winningTeam, null, null);
}
}, (2 + postGameWaiting) * 20L, TaskerTime.TICKS);
}
Expand Down Expand Up @@ -2135,6 +2164,7 @@ protected void spawnTeamPlayerOnGameStart(BedWarsPlayer player, TeamImpl team) {
)
);
});
team.getTeamMembers().add(new TeamImpl.Member(player.getUniqueId(), player.getName()));
}

protected void spawnSpectatorOnGameStart(BedWarsPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package org.screamingsandals.bedwars.game;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.screamingsandals.bedwars.api.Team;
import org.screamingsandals.bedwars.api.config.GameConfigurationContainer;
import org.screamingsandals.bedwars.api.game.target.Target;
Expand Down Expand Up @@ -49,6 +51,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

Expand All @@ -66,6 +69,7 @@ public class TeamImpl implements Team {
private final List<Location> chests = new ArrayList<>();
private boolean started;
private final List<BedWarsPlayer> players = new ArrayList<>();
private final List<Member> teamMembers = new ArrayList<>();
private Hologram hologram;
private Hologram protectHologram;
private final Random randomSpawn = new Random();
Expand Down Expand Up @@ -175,6 +179,7 @@ public void destroy() {

chests.clear();
players.clear();
teamMembers.clear();
started = false;
forced = false;
}
Expand Down Expand Up @@ -235,4 +240,10 @@ public boolean isDead() {
public Location getRandomSpawn() {
return teamSpawns.get(randomSpawn.nextInt(teamSpawns.size()));
}

@Data
public static class Member {
private final @NotNull UUID uuid;
private final @NotNull String name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,24 @@ public void onPlayerDeath(PlayerDeathEvent event) {
var gKiller = killer.as(BedWarsPlayer.class);
if (gKiller.getGame() == game) {
if (!onlyOnBedDestroy || !isBed) {
game.dispatchRewardCommands("player-kill", killer,
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_KILL, 10));
game.dispatchRewardCommands(
"player-kill",
killer,
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_KILL, 10),
game.getPlayerTeam(gKiller),
null,
null
);
}
if (!isBed) {
game.dispatchRewardCommands("player-final-kill", killer,
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_FINAL_KILL, 10));
game.dispatchRewardCommands(
"player-final-kill",
killer,
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_FINAL_KILL, 10),
game.getPlayerTeam(gKiller),
null,
null
);
}
if (team.isDead()) {
SpawnEffects.spawnEffect(game, gVictim, "game-effects.teamkill");
Expand Down Expand Up @@ -1325,26 +1337,52 @@ public void onMove(PlayerMoveEvent event) {

@OnEvent
public void onPlaceLiquid(PlayerBucketEvent event) {
if (event.cancelled() || event.action() != PlayerBucketEvent.Action.EMPTY) {
if (event.cancelled()) {
return;
}

var player = event.player();
if (PlayerManagerImpl.getInstance().isPlayerInGame(player)) {
var gPlayer = player.as(BedWarsPlayer.class);
var game = gPlayer.getGame();
var loc = event.blockClicked().location();

loc.add(event.blockFace().getDirection().normalize());
var loc = event.blockClicked().location().add(event.blockFace().getDirection().normalize());

var block = loc.getBlock();
if (game.getStatus() == GameStatus.RUNNING) {
if (block.block().isAir() || game.getRegion().isLocationModifiedDuringGame(block.location())) {
game.getRegion().addBuiltDuringGame(block.location());
Debug.info(player.getName() + " placed liquid");
if (game.getRegion().isLocationModifiedDuringGame(block.location())) {
return;
}

if (event.action() == PlayerBucketEvent.Action.EMPTY) {
if (Server.isVersion(1, 13) && event.bucket().is("minecraft:water_bucket") && event.blockClicked().block().getBoolean("waterlogged") != null) {
block = event.blockClicked();
game.getRegion().putOriginalBlock(block.location(), block.blockSnapshot());
game.getRegion().addBuiltDuringGame(block.location());
Debug.info(player.getName() + " placed liquid");
} else if (block.block().isAir()) {
game.getRegion().addBuiltDuringGame(block.location());
Debug.info(player.getName() + " placed liquid");
} else {
event.cancelled(true);
Debug.info(player.getName() + " placed liquid, cancelling");
}
} else {
event.cancelled(true);
Debug.info(player.getName() + " placed liquid, cancelling");
if (
BedWarsPlugin.isBreakableBlock(block.block())
|| (
Server.isVersion(1, 13)
&& event.bucket().is("minecraft:water_bucket")
&& event.blockClicked().block().getBoolean("waterlogged") != null
&& BedWarsPlugin.isBreakableBlock(Block.of("minecraft:water")) // Require breakable water
)
) {
game.getRegion().putOriginalBlock(block.location(), block.blockSnapshot());
game.getRegion().addBuiltDuringGame(block.location());
Debug.info(player.getName() + " broken liquid");
} else {
event.cancelled(true);
Debug.info(player.getName() + " broken liquid, cancelling");
}
}
} else if (game.getStatus() != GameStatus.DISABLED) {
event.cancelled(true);
Expand Down Expand Up @@ -1428,4 +1466,25 @@ public void onItemMerge(ItemMergeEvent event) {
}
}
}

@OnEvent
public void onSpectatorTeleported(PlayerTeleportEvent event) {
if (event.cancelled()) {
return;
}

if (event.cause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
return;
}

var game = PlayerManagerImpl.getInstance().getGameOfPlayer(event.player());

if (game.isEmpty()) {
return;
}

if (!ArenaUtils.isInArea(event.newLocation(), game.get().getPos1(), game.get().getPos2())) {
event.cancelled(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public void onTargetInvalidated(PostTargetInvalidatedEventImpl event) {
game.dispatchRewardCommands(
"player-destroy-bed",
initiator,
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_BED_DESTROY, 25)
game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_SCORES_BED_DESTROY, 25),
game.getTeamOfPlayer(initiator),
null,
null
);
}
}
Expand Down

0 comments on commit 678a2bb

Please sign in to comment.