Skip to content

Commit

Permalink
Improved Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
boiscljo committed May 7, 2022
1 parent a71cb9d commit 3763dc9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SBA_VERSION=1.5.6.6
SBA_VERSION=1.5.6.7

PAPER_LEGACY_VERSION=1.16.5
JUPITER_VERSION=5.7.2
Expand Down
1 change: 0 additions & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies {
exclude group: 'net.kyori'
}
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.github.pronze.sba.SBA;
import io.github.pronze.sba.lang.Message;
import io.github.pronze.sba.lib.lang.LanguageService;

import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -77,15 +79,15 @@ public void onBedWarsPlayerDeathEvent(BedwarsPlayerDeathMessageSendEvent event)
final var messages = LanguageService
.getInstance()
.get(MessageKeys.DEATH_MESSAGES_PVP_REGULAR)
.replace("%player%", victimTeamColorStr + event.getVictim().getName());
.replace("%player%", victimTeamColorStr + event.getVictim().getDisplayName()+ChatColor.RESET);


final var killer = victim.getKiller();
if (killer != null) {
final var killerTeam = event.getGame().getTeamOfPlayer(killer);
final var killerTeamColorStr = TeamColor.fromApiColor(killerTeam.getColor()).chatColor.toString();

messages.replace("%killer%", killerTeamColorStr + killer.getName());
messages.replace("%killer%", killerTeamColorStr + killer.getDisplayName()+ChatColor.RESET);
final var list = messages.toStringList();
event.setMessage(list.get(RANDOM.nextInt(list.size())));

Expand All @@ -96,8 +98,8 @@ public void onBedWarsPlayerDeathEvent(BedwarsPlayerDeathMessageSendEvent event)
message = LanguageService
.getInstance()
.get(MessageKeys.DEATH_MESSAGES_VOID_KILL)
.replace("%player%", victimTeamColorStr + victim.getName())
.replace("%killer%", killerTeamColorStr + killer.getName());
.replace("%player%", victimTeamColorStr + victim.getDisplayName()+ChatColor.RESET)
.replace("%killer%", killerTeamColorStr + killer.getDisplayName()+ChatColor.RESET);
event.setMessage(message.toString());
}
}
Expand All @@ -106,7 +108,9 @@ public void onBedWarsPlayerDeathEvent(BedwarsPlayerDeathMessageSendEvent event)
message = LanguageService
.getInstance()
.get(MessageKeys.DEATH_MESSAGES_GENERIC)
.replace("%player%", victimTeamColorStr + victim.getName());
.replace("%player%", victimTeamColorStr + victim.getDisplayName()+ChatColor.RESET);


event.setMessage(message.toString());

final var lastDamageCause = victim.getLastDamageCause();
Expand All @@ -115,7 +119,7 @@ public void onBedWarsPlayerDeathEvent(BedwarsPlayerDeathMessageSendEvent event)
message = LanguageService
.getInstance()
.get(MessageKeys.DEATH_MESSAGES_VOID_DEATH)
.replace("%player%", victimTeamColorStr + victim.getName());
.replace("%player%", victimTeamColorStr + victim.getDisplayName()+ChatColor.RESET);
event.setMessage(message.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.pronze.sba.wrapper.SBAPlayerWrapper;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -30,7 +31,8 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
final var player = event.getPlayer();
final var playerWrapper = PlayerMapper.wrapPlayer(player).as(SBAPlayerWrapper.class);

if (playerWrapper.getSettings().isToggled(PlayerSetting.IN_PARTY) && playerWrapper.getSettings().isToggled(PlayerSetting.PARTY_CHAT_ENABLED)) {
if (playerWrapper.getSettings().isToggled(PlayerSetting.IN_PARTY)
&& playerWrapper.getSettings().isToggled(PlayerSetting.PARTY_CHAT_ENABLED)) {
// PartyChatListener will take care of this.
return;
}
Expand All @@ -49,15 +51,19 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
.getInstance()
.node("chat-format", "game-chat", "all-chat-prefix").getString();

boolean all = false;
boolean spectator = false;
if (bedwarsPlayer.isSpectator) {
format = SBAConfig
.getInstance()
.node("chat-format", "game-chat", "format-spectator").getString();
spectator = true;
} else {
if (event.getMessage().startsWith(allChatPrefix)) {
format = SBAConfig
.getInstance()
.node("chat-format", "game-chat", "all-chat-format").getString();
all = true;
} else {
format = SBAConfig
.getInstance()
Expand All @@ -66,7 +72,8 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {

var colorName = game.getTeamOfPlayer(player).getColor().name().toUpperCase();
var teamName = game.getTeamOfPlayer(player).getName();
var color = TeamColor.fromApiColor(game.getTeamOfPlayer(player).getColor()).chatColor.toString();
var color = TeamColor.fromApiColor(game.getTeamOfPlayer(player).getColor()).chatColor
.toString();
format = format
.replace("%color%", color)
.replace("%color_name%", colorName)
Expand All @@ -79,14 +86,34 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
}

format = format
.replace("%player%", player.getName())
.replace("%player%", player.getDisplayName() + ChatColor.RESET)
.replace("%message%", message);
if (Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
format = PlaceholderAPI.setPlaceholders(player, format);
}

String finalFormat = format;
game.getConnectedPlayers().forEach(gamePlayer -> gamePlayer.sendMessage(finalFormat));
final String finalFormat = format;

if (all)
{
game.getConnectedPlayers().forEach(gamePlayer -> gamePlayer.sendMessage(finalFormat));
}
else if (spectator)
{
game.getConnectedPlayers().forEach(gamePlayer -> {
if(Main.getPlayerGameProfile(gamePlayer).isSpectator)
gamePlayer.sendMessage(finalFormat);
});
}
else // Team
{
var teamName = game.getTeamOfPlayer(player).getName();
game.getConnectedPlayers().forEach(gamePlayer -> {
if(teamName.equals(game.getTeamOfPlayer(gamePlayer).getName())||
Main.getPlayerGameProfile(gamePlayer).isSpectator)
gamePlayer.sendMessage(finalFormat);
});
}
}
} else if (game.getStatus() == GameStatus.WAITING) {
if (SBAConfig.getInstance().node("chat-format", "lobby-chat", "enabled").getBoolean()) {
Expand All @@ -102,7 +129,7 @@ public void onPlayerChat(AsyncPlayerChatEvent event) {
lobbyChatFormat = lobbyChatFormat
.replace("%color%", teamColor == null ? "" : teamColor)
.replace("%message%", event.getMessage())
.replace("%player%", player.getName());
.replace("%player%", player.getDisplayName() + ChatColor.RESET);

if (Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
lobbyChatFormat = PlaceholderAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ public void loadGamesInv() {
});

NPCs.forEach(npc -> {
Logger.trace("NPC at {} for mode {}", npc.location, npc.mode);
NPC n = createNpc(GameMode.fromInt(npc.mode), npc.location);
if (npc.skin != null) {
n.skin(new NPCSkin(
npc.skin,
npc.skin_signature));
try {
Logger.trace("NPC at {} for mode {}", npc.location, npc.mode);
NPC n = createNpc(GameMode.fromInt(npc.mode), npc.location);
if (npc.skin != null) {
n.skin(new NPCSkin(
npc.skin,
npc.skin_signature));
}
npc.npc = n;
} catch (Throwable t) {
Logger.error("{}", t);
}
npc.npc = n;
});
update();
}
Expand Down Expand Up @@ -236,12 +240,16 @@ public void addViewer(@NotNull Player player) {
NPCs.forEach(npc -> {
Logger.trace("npc::addViewer", player.getName());
if (npc.location.getWorld().equals(player.getWorld()))
npc.npc.addViewer(PlayerMapper.wrapPlayer(player));
if (npc.npc != null)
npc.npc.addViewer(PlayerMapper.wrapPlayer(player));
});
}

public void removeViewer(@NotNull Player player) {
NPCs.forEach(npc -> npc.npc.removeViewer(PlayerMapper.wrapPlayer(player)));
NPCs.forEach(npc -> {
if (npc.npc != null)
npc.npc.removeViewer(PlayerMapper.wrapPlayer(player));
});
}

@OnPreDisable
Expand Down

0 comments on commit 3763dc9

Please sign in to comment.