Update OnPlayerOnlineStatus to assign a class to a joining player

The constructor of OnPlayerOnlineStatus was updated to include WorldBorderApi, and its functionality now integrates FighterCreator for enhanced player handling. This change ensures proper application of a class and world border logic during player teleport and initialization.
This commit is contained in:
Teriuihi 2025-02-16 00:13:05 +01:00
parent 2242fea737
commit 57f2898451
2 changed files with 8 additions and 3 deletions

View File

@ -89,7 +89,7 @@ public class Main extends JavaPlugin {
pluginManager.registerEvents(new FlagTryCaptureEvent(flag), this);
pluginManager.registerEvents(new OnPlayerDeath(gameManager, worldBorderApi, this, flag), this);
pluginManager.registerEvents(new InventoryItemInteractionEvent(), this);
pluginManager.registerEvents(new OnPlayerOnlineStatus(gameManager, flag), this);
pluginManager.registerEvents(new OnPlayerOnlineStatus(gameManager, flag, worldBorderApi), this);
pluginManager.registerEvents(new GUIListener(), this);
}

View File

@ -5,8 +5,10 @@ import com.alttd.ctf.database.DiscordUserMapper;
import com.alttd.ctf.flag.Flag;
import com.alttd.ctf.game.GameManager;
import com.alttd.ctf.game.GamePhase;
import com.alttd.ctf.game_class.creation.FighterCreator;
import com.alttd.ctf.team.Team;
import com.alttd.ctf.team.TeamPlayer;
import com.github.yannicklamprecht.worldborder.api.WorldBorderApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.bukkit.attribute.Attribute;
@ -26,10 +28,12 @@ public class OnPlayerOnlineStatus implements Listener {
private final GameManager gameManager;
private final Flag flag;
private final WorldBorderApi worldBorderApi;
public OnPlayerOnlineStatus(GameManager gameManager, Flag flag) {
public OnPlayerOnlineStatus(GameManager gameManager, Flag flag, WorldBorderApi worldBorderApi) {
this.gameManager = gameManager;
this.flag = flag;
this.worldBorderApi = worldBorderApi;
}
@EventHandler
@ -61,7 +65,8 @@ public class OnPlayerOnlineStatus implements Listener {
} else {
teamPlayer = optionalTeamPlayer.get();
}
player.teleportAsync(teamPlayer.getTeam().getSpawnLocation());
FighterCreator.createFighter(teamPlayer.getTeam().getColor())
.apply(teamPlayer, worldBorderApi, gamePhase, true);
}
private void resetPlayer(Player player) {