Skip to content

Commit

Permalink
Removed all deprecated TextComponent from ServerSchedulers and added
Browse files Browse the repository at this point in the history
some messages in config file
  • Loading branch information
AlbertoRutigliano committed May 30, 2024
1 parent 95b4cc7 commit 56f9683
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/main/java/lar/minecraft/hg/ServerSchedulers.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ public void run() {
for(Player p : SpigotPlugin.server.getOnlinePlayers()) {
p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText(
MessageUtils.getMessage(MessageKey.waiting_phase_min_players, SpigotPlugin.server.getOnlinePlayers().size(), minimumPlayers)));
new TextComponent(MessageUtils.getMessage(MessageKey.waiting_phase_min_players, SpigotPlugin.server.getOnlinePlayers().size(), minimumPlayers)));
}
} else {
lobbyPhase();
Expand Down Expand Up @@ -124,7 +123,7 @@ public void run() {
for(Player p : SpigotPlugin.server.getOnlinePlayers()) {
p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText("Game will start in " + Math.abs(passedSeconds) + " seconds"));
new TextComponent("Game will start in " + Math.abs(passedSeconds) + " seconds"));
}
if (passedSeconds == 0) {
safeAreaPhase();
Expand All @@ -143,7 +142,7 @@ public void safeAreaPhase() {

// Notify all players that Hunger Games is starting
ServerManager.getLivingPlayers().forEach(p -> {
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("It's starting the Hunger Games!"));
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(MessageUtils.getMessage(MessageKey.safe_area_phase_alert)));
p.setGameMode(GameMode.SURVIVAL);
p.teleport(world.getSpawnLocation());

Expand All @@ -162,13 +161,12 @@ public void run() {
}
long passedSeconds = (execTime - safeAreaTime) / 20;

ServerManager.getLivingPlayers().forEach(p -> p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText("Safe area expires in " + Math.abs(passedSeconds) + " seconds")));
ServerManager.getLivingPlayers().forEach(
p -> p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
new TextComponent(MessageUtils.getMessage(MessageKey.safe_area_expires_alert, Math.abs(passedSeconds))))
);
if (passedSeconds == 0) {
ServerManager.getLivingPlayers().forEach(p -> p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText("It's Hunger Games tiiiiiiiiime!")));
playingPhase();
server.getScheduler().cancelTask(safeAreaPhaseTaskId);
}
Expand All @@ -183,6 +181,9 @@ public void playingPhase() {
worldBorderCollapseTime = 0;
winnerCelebrationsTime = 0;
server.setIdleTimeout(idleTimeout);
ServerManager.getLivingPlayers().forEach(p -> p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
new TextComponent(MessageUtils.getMessage(MessageKey.playing_phase_alert))));
DatabaseManager.saveStartingDateTime(config.getInt("server.id", 1), currentHGGameId);
playingPhaseTaskId = server.getScheduler().scheduleSyncRepeatingTask(SpigotPlugin.getPlugin(SpigotPlugin.class), new Runnable() {
public void run() {
Expand Down Expand Up @@ -242,7 +243,7 @@ public void run() {
for(Player p : SpigotPlugin.server.getOnlinePlayers()) {
p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText("A new Hunger Games will start in " + Math.abs(passedSeconds) + " seconds. Server will be restarted"));
new TextComponent(MessageUtils.getMessage(MessageKey.safe_area_expires_alert, Math.abs(passedSeconds))));
}
if (passedSeconds == 0) {
SpigotPlugin.setPhase(HGPhase.WAITING_FOR_HG);
Expand Down Expand Up @@ -332,8 +333,7 @@ public void run() {
for(Player p : SpigotPlugin.server.getOnlinePlayers()) {
p.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText(MessageUtils.getMessage(MessageKey.supply_drop_alert, Math.abs(passedSeconds))));

new TextComponent(MessageUtils.getMessage(MessageKey.supply_drop_alert, Math.abs(passedSeconds))));
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/lar/minecraft/hg/commands/TestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import lar.minecraft.hg.MessageUtils;
import lar.minecraft.hg.ServerSchedulers;
import lar.minecraft.hg.SpigotPlugin;
import lar.minecraft.hg.enums.MessageKey;
import lar.minecraft.hg.managers.ServerManager;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text;

public class TestCommand implements CommandExecutor {

Expand All @@ -25,7 +31,16 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
String cmdName = cmd.getName().toLowerCase();

if (cmdName.equals("test")) {
sender.sendMessage(MessageUtils.getMessage(args[0], sender.getName()));
TextComponent message = new TextComponent("PROVOLA");
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/AlbertoRutigliano/minecraft-hunger-games"));
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Hello World")));
sender.spigot().sendMessage(message);

Player player = (Player) sender;
player.spigot().sendMessage(
ChatMessageType.ACTION_BAR,
new TextComponent(MessageUtils.getMessage(MessageKey.supply_drop, 0, 1, 2)));

//new ServerSchedulers(plugin).waitingPhase();
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/lar/minecraft/hg/enums/MessageKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ public enum MessageKey {
supply_drop_alert,
supply_drop,
last_match_win,
waiting_phase_min_players
waiting_phase_min_players,
safe_area_phase_alert,
safe_area_expires_alert,
playing_phase_alert,
server_to_restart_alert
}
6 changes: 5 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ class_wrong: "There's no &6&m{0}&7 class"
supply_drop_alert: "&fA &6supply drop chest &fwill be spawned in {0} seconds"
supply_drop: "Supply chest dropped at XYZ:&2&o {0} / {1} / {2}"
last_match_win: "You have &6won the last Hunger Games&7! In this game you can choose a &6premium class"
waiting_phase_min_players: "The Hunger Games starts when there is the minimum number of players: {0}/{1}"
waiting_phase_min_players: "The Hunger Games starts when there is the minimum number of players: {0}/{1}"
safe_area_phase_alert: "It's starting the Hunger Games!"
safe_area_expires_alert: "Safe area expires in {0} seconds"
playing_phase_alert: "It's Hunger Games time!"
server_to_restart_alert: "A new Hunger Games will start in {0} seconds. Server will be restarted"

0 comments on commit 56f9683

Please sign in to comment.