Skip to content

Commit bcb9680

Browse files
committed
feat: port 0.2.41 features, fixed compat with latest slib
- eb2790c feat: go to snapshot, add playSound boolean to PlayerKilledEvent, move the event up a little - f52f218 fix: skip chunk ticket claiming if the process fails - 65185c7 feat: add BedwarsPlayerRespawnedIngameEvent
1 parent 26c0cd3 commit bcb9680

File tree

9 files changed

+52
-28
lines changed

9 files changed

+52
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
A highly flexible BedWars plugin with wide Minecraft version support, originally inspired by BedwarsRel.
1111

12-
Supported versions: \[1.8.8 - 1.21.8\]. Recommended version: \[1.21.8\]
12+
Supported versions: \[1.8.8 - 1.21.10\]. Recommended version: \[1.21.10\]
1313

1414
## Support
1515
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.

api/src/main/java/org/screamingsandals/bedwars/api/events/PlayerKilledEvent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public interface PlayerKilledEvent {
3838

3939
List<? extends ItemStackHolder> getDrops();
4040

41+
boolean isPlaySound();
42+
43+
void setPlaySound(boolean playSound);
44+
4145
static void handle(Object plugin, Consumer<PlayerKilledEvent> consumer) {
4246
BedwarsAPI.getInstance().getEventUtils().handle(plugin, PlayerKilledEvent.class, consumer);
4347
}

api/src/main/java/org/screamingsandals/bedwars/api/events/PlayerRespawnedEvent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.jetbrains.annotations.ApiStatus;
2323
import org.screamingsandals.bedwars.api.BedwarsAPI;
24+
import org.screamingsandals.bedwars.api.Team;
2425
import org.screamingsandals.bedwars.api.game.LocalGame;
2526
import org.screamingsandals.bedwars.api.player.BWPlayer;
2627

@@ -32,6 +33,8 @@ public interface PlayerRespawnedEvent {
3233

3334
BWPlayer getPlayer();
3435

36+
Team getTeam();
37+
3538
static void handle(Object plugin, Consumer<PlayerRespawnedEvent> consumer) {
3639
BedwarsAPI.getInstance().getEventUtils().handle(plugin, PlayerRespawnedEvent.class, consumer);
3740
}

plugin/bukkit/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ runTestServer {
2525
versions(
2626
org.screamingsandals.gradle.run.config.Platform.PAPER,
2727
listOf(
28+
"1.21.10",
2829
"1.21.8",
2930
"1.21.4",
3031
"1.21.3",

plugin/common/src/main/java/org/screamingsandals/bedwars/commands/DumpCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ protected void construct(Command.Builder<CommandSender> commandSenderWrapperBuil
126126
"monsters", world.isSpawningOfMonstersAllowed()
127127
),
128128
"maxHeight", world.getMaxY(),
129-
"minHeight", world.getMinY(),
130-
"keepSpawnInMemory", world.isSpawnKeptInMemory()
129+
"minHeight", world.getMinY()
131130
)).collect(Collectors.toList()),
132131
"plugins", Plugins.getAllPlugins().stream().map(plugin -> Map.of(
133132
"enabled", plugin.isEnabled(),

plugin/common/src/main/java/org/screamingsandals/bedwars/events/PlayerKilledEventImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ public class PlayerKilledEventImpl implements PlayerKilledEvent, Event {
3434
private final BedWarsPlayer killer;
3535
private final BedWarsPlayer player;
3636
private final List<ItemStack> drops;
37+
private boolean playSound;
3738
}

plugin/common/src/main/java/org/screamingsandals/bedwars/events/PlayerRespawnedEventImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import lombok.Data;
2323
import org.screamingsandals.bedwars.api.events.PlayerRespawnedEvent;
2424
import org.screamingsandals.bedwars.game.GameImpl;
25+
import org.screamingsandals.bedwars.game.TeamImpl;
2526
import org.screamingsandals.bedwars.player.BedWarsPlayer;
2627
import org.screamingsandals.lib.event.Event;
2728

2829
@Data
2930
public class PlayerRespawnedEventImpl implements PlayerRespawnedEvent, Event {
3031
private final GameImpl game;
3132
private final BedWarsPlayer player;
33+
private final TeamImpl team;
3234
}

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ public void makePlayerFromSpectator(BedWarsPlayer gamePlayer) {
12041204
healthIndicator.addTrackedPlayer(gamePlayer);
12051205
}
12061206

1207-
EventManager.fire(new PlayerRespawnedEventImpl(this, gamePlayer));
1207+
EventManager.fire(new PlayerRespawnedEventImpl(this, gamePlayer, currentTeam));
12081208
});
12091209
}
12101210
}
@@ -1298,7 +1298,11 @@ public void rebuild() {
12981298

12991299
if (!chunksWithTickets.isEmpty()) {
13001300
for (var chunk : chunksWithTickets) {
1301-
chunk.removePluginChunkTicket();
1301+
try {
1302+
chunk.removePluginChunkTicket();
1303+
} catch (Exception ex) {
1304+
BedWarsPlugin.getInstance().getLogger().warn("Unable to remove plugin chunk ticket", ex);
1305+
}
13021306
}
13031307
chunksWithTickets.clear();
13041308
}
@@ -1932,13 +1936,18 @@ public void configureChunkTickets() {
19321936
int minZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()) >> 4;
19331937
int maxZ = Math.max(pos1.getBlockZ(), pos2.getBlockZ()) >> 4;
19341938

1935-
for (int x = minX; x <= maxX; x++) {
1936-
for (int z = minZ; z <= maxZ; z++) {
1937-
var chunk = world.getChunkAt(x, z);
1938-
if (chunk != null && chunk.addPluginChunkTicket()) {
1939-
chunksWithTickets.add(chunk);
1939+
1940+
try {
1941+
for (int x = minX; x <= maxX; x++) {
1942+
for (int z = minZ; z <= maxZ; z++) {
1943+
var chunk = world.getChunkAt(x, z);
1944+
if (chunk != null && chunk.addPluginChunkTicket()) {
1945+
chunksWithTickets.add(chunk);
1946+
}
19401947
}
19411948
}
1949+
} catch (Exception ex) {
1950+
BedWarsPlugin.getInstance().getLogger().warn("Failed to claim chunk tickets, skipping", ex);
19421951
}
19431952
}
19441953

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ public void onPlayerDeath(PlayerDeathEvent event) {
201201
boolean onlyOnBedDestroy = game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.STATISTICS_BED_DESTROYED_KILLS, false);
202202

203203
var killer = event.killer();
204-
if (killer != null && PlayerManagerImpl.getInstance().isPlayerInGame(killer)) {
205-
var gKiller = killer.as(BedWarsPlayer.class);
204+
var gKiller = killer != null && PlayerManagerImpl.getInstance().isPlayerInGame(killer) ? killer.as(BedWarsPlayer.class) : null;
205+
206+
var killedEvent = new PlayerKilledEventImpl(game, gKiller, gVictim, drops);
207+
EventManager.fire(killedEvent);
208+
209+
if (gKiller != null) {
206210
if (gKiller.getGame() == game) {
207211
if (!onlyOnBedDestroy || !isBed) {
208212
game.dispatchRewardCommands(
@@ -227,19 +231,23 @@ public void onPlayerDeath(PlayerDeathEvent event) {
227231
if (team.isDead()) {
228232
SpawnEffects.spawnEffect(game, gVictim, "game-effects.teamkill");
229233

230-
killer.playSound(SoundStart.sound(
231-
ResourceLocation.of(MainConfig.getInstance().node("sounds", "team_kill", "sound").getString("entity.player.levelup")),
232-
SoundSource.AMBIENT,
233-
(float) MainConfig.getInstance().node("sounds", "team_kill", "volume").getDouble(),
234-
(float) MainConfig.getInstance().node("sounds", "team_kill", "pitch").getDouble()
235-
));
234+
if (killedEvent.isPlaySound()) {
235+
killer.playSound(SoundStart.sound(
236+
ResourceLocation.of(MainConfig.getInstance().node("sounds", "team_kill", "sound").getString("entity.player.levelup")),
237+
SoundSource.AMBIENT,
238+
(float) MainConfig.getInstance().node("sounds", "team_kill", "volume").getDouble(),
239+
(float) MainConfig.getInstance().node("sounds", "team_kill", "pitch").getDouble()
240+
));
241+
}
236242
} else {
237-
killer.playSound(SoundStart.sound(
238-
ResourceLocation.of(MainConfig.getInstance().node("sounds", "player_kill", "sound").getString("entity.generic.big_fall")),
239-
SoundSource.AMBIENT,
240-
(float) MainConfig.getInstance().node("sounds", "player_kill", "volume").getDouble(),
241-
(float) MainConfig.getInstance().node("sounds", "player_kill", "pitch").getDouble()
242-
));
243+
if (killedEvent.isPlaySound()) {
244+
killer.playSound(SoundStart.sound(
245+
ResourceLocation.of(MainConfig.getInstance().node("sounds", "player_kill", "sound").getString("entity.generic.big_fall")),
246+
SoundSource.AMBIENT,
247+
(float) MainConfig.getInstance().node("sounds", "player_kill", "volume").getDouble(),
248+
(float) MainConfig.getInstance().node("sounds", "player_kill", "pitch").getDouble()
249+
));
250+
}
243251
if (!isBed) {
244252
EconomyUtils.deposit(killer, game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.ECONOMY_REWARD_FINAL_KILL, 0.0));
245253
} else {
@@ -249,9 +257,6 @@ public void onPlayerDeath(PlayerDeathEvent event) {
249257
}
250258
}
251259

252-
var killedEvent = new PlayerKilledEventImpl(game, killer != null && PlayerManagerImpl.getInstance().isPlayerInGame(killer) ? killer.as(BedWarsPlayer.class) : null, gVictim, drops);
253-
EventManager.fire(killedEvent);
254-
255260
if (PlayerStatisticManager.isEnabled()) {
256261
var diePlayer = PlayerStatisticManager.getInstance().getStatistic(victim);
257262
PlayerStatisticImpl killerPlayer;
@@ -511,7 +516,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
511516
Debug.info(event.player().getName() + " is going to play the game");
512517
event.location(gPlayer.getGame().getPlayerTeam(gPlayer).getRandomSpawn());
513518

514-
var respawnEvent = new PlayerRespawnedEventImpl(game, gPlayer);
519+
var respawnEvent = new PlayerRespawnedEventImpl(game, gPlayer, team);
515520
EventManager.fire(respawnEvent);
516521

517522
if (game.getConfigurationContainer().getOrDefault(GameConfigurationContainer.RESPAWN_PROTECTION_ENABLED, true)) {

0 commit comments

Comments
 (0)