add /tc <message>, fix scripts, increment version

This commit is contained in:
grng 2024-07-25 13:32:04 +01:00
parent 696e2b09aa
commit 01aeefaaa3
4 changed files with 46 additions and 27 deletions

View file

@ -13,7 +13,7 @@
<groupId>rip.iwakura</groupId> <groupId>rip.iwakura</groupId>
<artifactId>CivilCore</artifactId> <artifactId>CivilCore</artifactId>
<version>0.1b</version> <version>0.1c</version>
<repositories> <repositories>
<repository> <repository>

View file

@ -1,4 +1,3 @@
# Check if the test_server directory exists, if not, create it
if (-not (Test-Path -Path test_server)) { if (-not (Test-Path -Path test_server)) {
New-Item -ItemType Directory -Path test_server New-Item -ItemType Directory -Path test_server
} }

View file

@ -43,7 +43,7 @@ public class TeamChatCommand implements CommandExecutor {
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "TEAM" + ChatColor.GREEN + " channel"); p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "TEAM" + ChatColor.GREEN + " channel");
} }
return true; return true;
} }
String message = String.join(" ", args); String message = String.join(" ", args);
@ -52,32 +52,18 @@ public class TeamChatCommand implements CommandExecutor {
boolean inTeamChat = civilCore.teamChatRegister.contains(p); boolean inTeamChat = civilCore.teamChatRegister.contains(p);
DbPlayer dbPlayer = civilCore.db.getPlayerByName(player_name); DbPlayer dbPlayer = civilCore.db.getPlayerByName(player_name);
/*String prefix = (inTeamChat ? ChatColor.DARK_GREEN + "TEAM >" + ChatColor.RESET : "")
+ (dbPlayer.team.prefix == null ?
"" :
ChatColor.translateAlternateColorCodes('&', inTeamChat ? "" : "[" + dbPlayer.team.prefix + "]"));*/
/*if (civilCore.teamChatRegister.contains(p)) { if (inTeamChat) {
// Send message to global chat
civilCore.teamChatRegister.remove(p); civilCore.teamChatRegister.remove(p);
// Bukkit.broadcastMessage(ChatColor.DARK_GREEN + "TEAM > " + ChatColor.GREEN + p.getName() + ": " + message); String formatted = String.format("%s%s: %s", getPrefix(player_name, false) + " ", player_name, message);
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
Bukkit.broadcastMessage(formatted); Bukkit.broadcastMessage(formatted);
civilCore.bot.sendMessage(p, message);
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
} else { } else {
// Send message to team chat
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message); String formatted = String.format("%s%s: %s", getPrefix(player_name, true) + " ", player_name, message);
Bukkit.broadcastMessage(formatted);
civilCore.teamChatRegister.remove(p);
}*/
if (!inTeamChat) {
civilCore.teamChatRegister.remove(p);
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
Bukkit.broadcastMessage(formatted);
civilCore.teamChatRegister.add(p);
} else {
civilCore.teamChatRegister.add(p);
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
List<DbPlayer> players = civilCore.db.getPlayersInTeam(dbPlayer.team.name); List<DbPlayer> players = civilCore.db.getPlayersInTeam(dbPlayer.team.name);
if (players == null) return true; if (players == null) return true;
@ -87,12 +73,11 @@ public class TeamChatCommand implements CommandExecutor {
if (team_p == null) continue; if (team_p == null) continue;
team_p.sendMessage(message); team_p.sendMessage(formatted);
} }
civilCore.teamChatRegister.remove(p); civilCore.teamChatRegister.remove(p);
} }
return true; return true;
} }
} }

View file

@ -3,6 +3,7 @@ package rip.iwakura.civilcore.discord;
import java.util.EnumSet; import java.util.EnumSet;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.checkerframework.common.reflection.qual.GetConstructor; import org.checkerframework.common.reflection.qual.GetConstructor;
@ -17,6 +18,7 @@ import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import rip.iwakura.civilcore.CivilCore; import rip.iwakura.civilcore.CivilCore;
import net.dv8tion.jda.api.events.session.ReadyEvent; import net.dv8tion.jda.api.events.session.ReadyEvent;
import rip.iwakura.civilcore.types.DbPlayer;
public class Discord extends ListenerAdapter { public class Discord extends ListenerAdapter {
private String token; private String token;
@ -45,15 +47,48 @@ public class Discord extends ListenerAdapter {
} }
public void sendMessage(AsyncPlayerChatEvent e) { public void sendMessage(AsyncPlayerChatEvent e) {
DbPlayer dbPlayer = civilCore.db.getPlayerByName(e.getPlayer().getName());
String prefix = (dbPlayer.team.prefix == null ?
"" :
"[" + dbPlayer.team.prefix + "]");
String player_name = e.getPlayer().getName(); String player_name = e.getPlayer().getName();
WebhookMessageBuilder builder = new WebhookMessageBuilder() WebhookMessageBuilder builder = new WebhookMessageBuilder()
.setUsername(player_name) .setUsername(prefix + " " + player_name)
.setAvatarUrl(String.format("https://mc-heads.net/avatar/%s", player_name)) .setAvatarUrl(String.format("https://mc-heads.net/avatar/%s", player_name))
.setContent(e.getMessage()); .setContent(e.getMessage());
webhook.send(builder.build()); webhook.send(builder.build());
//channel.sendMessage(String.format("%s: %s", e.getPlayer().getName(), e.getMessage())).complete(); //channel.sendMessage(String.format("%s: %s", e.getPlayer().getName(), e.getMessage())).complete();
} }
public void sendMessage(Player p, String message) {
DbPlayer dbPlayer = civilCore.db.getPlayerByName(p.getName());
String prefix = (dbPlayer.team.prefix == null ?
"" :
"[" + dbPlayer.team.prefix + "]");
WebhookMessageBuilder builder = new WebhookMessageBuilder()
.setUsername(prefix + " " + p.getName())
.setAvatarUrl(String.format("https://mc-heads.net/avatar/%s", p.getName()))
.setContent(message);
webhook.send(builder.build());
//channel.sendMessage(String.format("%s: %s", p.getName(), message)).complete();
}
public void sendMessage(String message, String name) {
DbPlayer dbPlayer = civilCore.db.getPlayerByName(name);
String prefix = (dbPlayer.team.prefix == null ?
"" :
"[" + dbPlayer.team.prefix + "]");
WebhookMessageBuilder builder = new WebhookMessageBuilder()
.setUsername(prefix + " " + name)
.setAvatarUrl(String.format("https://mc-heads.net/avatar/%s", name))
.setContent(message);
webhook.send(builder.build());
//channel.sendMessage(String.format("%s: %s", name, message)).complete();
}
@Override @Override
public void onReady(ReadyEvent e) { public void onReady(ReadyEvent e) {
this.channel = bot.getTextChannelById(channelId); this.channel = bot.getTextChannelById(channelId);