Skip to content

Commit

Permalink
feat: go to snapshot, (not tested) new "reward" commands
Browse files Browse the repository at this point in the history
* player-game-start
* game-start
* player-early-leave
* team-win
* player-team-win
  • Loading branch information
Misat11 committed Jul 9, 2024
1 parent 636ab89 commit a2fb790
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

allprojects {
group = 'org.screamingsandals.bedwars'
version = '0.2.33.1'
version = '0.2.34-SNAPSHOT'
}

if (version.toString().endsWith('-SNAPSHOT')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,31 @@ public void createFiles() {
add("/example {player} 10");
}
});
checkOrSetConfig(modify, "rewards.player-game-start", new ArrayList<String>() {
{
add("/example {player} 10");
}
});
checkOrSetConfig(modify, "rewards.player-early-leave", new ArrayList<String>() {
{
add("/example {player} {death} 10");
}
});
checkOrSetConfig(modify, "rewards.team-win", new ArrayList<String>() {
{
add("/example {team} 10");
}
});
checkOrSetConfig(modify, "rewards.player-team-win", new ArrayList<String>() {
{
add("/example {team} {death} 10");
}
});
checkOrSetConfig(modify, "rewards.game-start", new ArrayList<String>() {
{
add("/example Hello World!");
}
});

checkOrSetConfig(modify, "lore.generate-automatically", true);
checkOrSetConfig(modify, "lore.text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.screamingsandals.bedwars.game;

import lombok.Data;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand All @@ -32,12 +33,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static org.screamingsandals.bedwars.lib.lang.I.i18nc;

public class CurrentTeam implements RunningTeam {
public final Team teamInfo;
public final List<GamePlayer> players = new ArrayList<>();
public final List<Member> teamMembers = new ArrayList<>();
private org.bukkit.scoreboard.Team scoreboardTeam;
private Inventory chestInventory;
private List<Block> chests = new ArrayList<>();
Expand Down Expand Up @@ -201,4 +204,10 @@ public Game getGame() {
public int countTeamChests() {
return chests.size();
}

@Data
public static class Member {
private final UUID uuid;
private final String name;
}
}
50 changes: 44 additions & 6 deletions plugin/src/main/java/org/screamingsandals/bedwars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public void bedDestroyed(Location loc, Player broker, boolean isItBedBlock, bool
}

dispatchRewardCommands("player-destroy-bed", broker,
Main.getConfigurator().config.getInt("statistics.scores.bed-destroy", 25));
Main.getConfigurator().config.getInt("statistics.scores.bed-destroy", 25), (CurrentTeam) getTeamOfPlayer(broker), null, null);
}
}
}
Expand Down Expand Up @@ -888,6 +888,10 @@ public void internalLeavePlayer(GamePlayer gamePlayer) {
updateScoreboard();
}
}

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

if (Main.isPlayerStatisticsEnabled()) {
Expand Down Expand Up @@ -1996,6 +2000,7 @@ public void run() {
Main.getConfigurator().config.getString("sounds.game_start.sound"),
Sounds.ENTITY_PLAYER_LEVELUP, (float) Main.getConfigurator().config.getDouble("sounds.game_start.volume"), (float) Main.getConfigurator().config.getDouble("sounds.game_start.pitch"));
});
team.teamMembers.add(new CurrentTeam.Member(player.player.getUniqueId(), player.player.getName()));
}
}

Expand Down Expand Up @@ -2114,6 +2119,11 @@ public void run() {
Main.getInstance().getServer().getPluginManager().callEvent(startedEvent);
Main.getInstance().getServer().getPluginManager().callEvent(statusE);
updateScoreboard();

for (GamePlayer player : players) {
Game.this.dispatchRewardCommands("player-game-start", player.player, 0, getPlayerTeam(player), null, null);
}
Game.this.dispatchRewardCommands("game-start", null, 0);
}
}
// Phase 6.2: If status is same as before
Expand Down Expand Up @@ -2184,9 +2194,9 @@ public void run() {
PlayerStatistic statistic = Main.getPlayerStatisticsManager()
.getStatistic(player.player);
Game.this.dispatchRewardCommands("player-win-run-immediately", player.player,
statistic.getScore());
statistic.getScore(), t, null, null);
} else {
Game.this.dispatchRewardCommands("player-win-run-immediately", player.player, 0);
Game.this.dispatchRewardCommands("player-win-run-immediately", player.player, 0, t, null, null);
}

final Player pl = player.player;
Expand All @@ -2198,9 +2208,9 @@ public void run() {
PlayerStatistic statistic = Main.getPlayerStatisticsManager()
.getStatistic(player.player);
Game.this.dispatchRewardCommands("player-win", pl,
statistic.getScore());
statistic.getScore(), t, null, null);
} else {
Game.this.dispatchRewardCommands("player-win", pl, 0);
Game.this.dispatchRewardCommands("player-win", pl, 0, t, null, null);
}
}

Expand All @@ -2214,6 +2224,12 @@ public void run() {
}
}
}

Game.this.dispatchRewardCommands("team-win", null, 0, t, null, null);
for (CurrentTeam.Member member : t.teamMembers) {
Game.this.dispatchRewardCommands("player-team-win", null, 0, t, t.getConnectedPlayers().stream().anyMatch(p -> p.getUniqueId().equals(member.getUuid())), member);
}

break;
}
}
Expand Down Expand Up @@ -3410,14 +3426,36 @@ public void setSpawnerDisableMerge(InGameConfigBooleanConstants spawnerDisableMe
}

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

public void dispatchRewardCommands(String type, Player player, int score, CurrentTeam team, Boolean deathStatus, CurrentTeam.Member member) {
if (!Main.getConfigurator().config.getBoolean("rewards.enabled")) {
return;
}

List<String> list = Main.getConfigurator().config.getStringList("rewards." + type);
for (String command : list) {
command = command.replace("{player}", player.getName());
if (command.startsWith("/example ")) {
continue; // 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.teamInfo.name);
}
if (deathStatus != null) {
command = command.replace("{death}", deathStatus ? "true" : "false");
}
command = command.startsWith("/") ? command.substring(1) : command;
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public void onPlayerDeath(PlayerDeathEvent event) {
if (gKiller.getGame() == game) {
if (!onlyOnBedDestroy || !isBed) {
game.dispatchRewardCommands("player-kill", killer,
Main.getConfigurator().config.getInt("statistics.scores.kill", 10));
Main.getConfigurator().config.getInt("statistics.scores.kill", 10), game.getPlayerTeam(gKiller), null, null);
}
if (!isBed) {
game.dispatchRewardCommands("player-final-kill", killer,
Main.getConfigurator().config.getInt("statistics.scores.final-kill", 0));
Main.getConfigurator().config.getInt("statistics.scores.final-kill", 0), game.getPlayerTeam(gKiller), null, null);
}
if (team.isDead()) {
SpawnEffects.spawnEffect(game, victim, "game-effects.teamkill");
Expand Down

0 comments on commit a2fb790

Please sign in to comment.