Revamped in-game Discord mention system.
Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
This commit is contained in:
parent
fa10bf7003
commit
d5645f3b0a
@ -58,12 +58,37 @@ public class FactionChatHandler extends ListenerAdapter {
|
|||||||
} else {
|
} else {
|
||||||
webhookClient = textChannel.createWebhook(Conf.webhookName).complete().newClient().build();
|
webhookClient = textChannel.createWebhook(Conf.webhookName).complete().newClient().build();
|
||||||
}
|
}
|
||||||
if (message.contains("@")) {
|
if (message.contains("@") && message.contains("#")) {
|
||||||
List<String> x = new ArrayList<>(Arrays.asList(message.split(" ")));
|
List<String> x = new ArrayList<>(Arrays.asList(message.split(" ")));
|
||||||
for (String y : x) {
|
for (String y : x) {
|
||||||
if (y.contains("@")) {
|
if (y.contains("@") && y.contains("#")) {
|
||||||
if (!Discord.jda.getUsersByName(y.replace("@", ""), false).isEmpty() && Discord.jda.getUsersByName(y.replace("@", ""), false).size() < 2) {
|
String[] target = y.replace("@", "").split("#");
|
||||||
x.set(x.indexOf(y), Discord.jda.getUsersByName(y.replace("@", ""), false).get(0).getAsMention());
|
for (User u : Discord.jda.getUsersByName(target[0], false)) {
|
||||||
|
if (u.getDiscriminator().equals(target[1])) {
|
||||||
|
x.set(x.indexOf(y), u.getAsMention());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (y.contains("@")) {
|
||||||
|
List<Integer> ii = new ArrayList<>();
|
||||||
|
int i = x.indexOf(y);
|
||||||
|
String mention = "";
|
||||||
|
while (i <= x.size() - 1) {
|
||||||
|
mention = mention + " " + x.get(i);
|
||||||
|
ii.add(i);
|
||||||
|
if (mention.contains("#")) {break;}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (mention.contains("#")) {
|
||||||
|
String[] mentionA = mention.replace(" @", "").split("#");
|
||||||
|
|
||||||
|
for (User u : Discord.jda.getUsersByName(mentionA[0], false)) {
|
||||||
|
if (u.getDiscriminator().equals(mentionA[1])) {
|
||||||
|
for (Integer l : ii) {
|
||||||
|
x.set(l, "");
|
||||||
|
}
|
||||||
|
x.set(ii.get(0), u.getAsMention());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.massivecraft.factions.cmd.CmdFGlobal;
|
|||||||
import com.massivecraft.factions.cmd.CmdFly;
|
import com.massivecraft.factions.cmd.CmdFly;
|
||||||
import com.massivecraft.factions.cmd.CmdSeeChunk;
|
import com.massivecraft.factions.cmd.CmdSeeChunk;
|
||||||
import com.massivecraft.factions.cmd.logout.LogoutHandler;
|
import com.massivecraft.factions.cmd.logout.LogoutHandler;
|
||||||
|
import com.massivecraft.factions.discord.Discord;
|
||||||
import com.massivecraft.factions.event.FPlayerEnteredFactionEvent;
|
import com.massivecraft.factions.event.FPlayerEnteredFactionEvent;
|
||||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||||
@ -26,6 +27,9 @@ import com.massivecraft.factions.zcore.util.TagUtil;
|
|||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.CoreProtectAPI;
|
import net.coreprotect.CoreProtectAPI;
|
||||||
|
import net.dv8tion.jda.core.entities.Member;
|
||||||
|
import net.dv8tion.jda.core.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.core.entities.User;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -1024,9 +1028,51 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDisconnect(PlayerQuitEvent e) {
|
public void onDisconnect(PlayerQuitEvent e) {
|
||||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getPlayer());
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getPlayer());
|
||||||
if (fPlayer.isInFactionsChest()) fPlayer.setInFactionsChest(false);
|
if (fPlayer.isInFactionsChest()) fPlayer.setInFactionsChest(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTab(PlayerChatTabCompleteEvent e) {
|
||||||
|
if (!Discord.useDiscord) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String[] msg = e.getChatMessage().split(" ");
|
||||||
|
if (msg.length == 0 | !msg[msg.length - 1].contains("@")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FPlayer fp = FPlayers.getInstance().getByPlayer(e.getPlayer());
|
||||||
|
if (fp == null | fp.getChatMode() != ChatMode.FACTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Faction f = fp.getFaction();
|
||||||
|
if (f == null | f.isSystemFaction()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (f.getGuildId() == null | f.getFactionChatChannelId() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Discord.jda.getGuildById(f.getGuildId()) == null | Discord.jda.getGuildById(f.getGuildId()).getTextChannelById(f.getFactionChatChannelId()) == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TextChannel t = Discord.jda.getGuildById(f.getGuildId()).getTextChannelById(f.getFactionChatChannelId());
|
||||||
|
String target = msg[msg.length - 1].replace("@", "");
|
||||||
|
List<String> targets = new ArrayList<>();
|
||||||
|
if (target.equals("")) {
|
||||||
|
for (Member m : t.getMembers()) {
|
||||||
|
targets.add("@" + m.getUser().getName() + "#" + m.getUser().getDiscriminator());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Member m : t.getMembers()) {
|
||||||
|
if (m.getEffectiveName().contains(target) | m.getUser().getName().contains(target)){
|
||||||
|
targets.add("@" + m.getUser().getName() + "#" + m.getUser().getDiscriminator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.getTabCompletions().clear();
|
||||||
|
e.getTabCompletions().addAll(targets);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user