Skip to content

Commit

Permalink
Fixed GOT_INVITE not supported hex colors (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jun 16, 2022
1 parent 562c1bb commit 7b2edff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
Expand Up @@ -10,10 +10,6 @@
import com.bgsoftware.superiorskyblock.commands.arguments.CommandArguments;
import com.bgsoftware.superiorskyblock.island.permissions.IslandPrivileges;
import com.bgsoftware.superiorskyblock.lang.Message;
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 org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -83,13 +79,15 @@ public void execute(SuperiorSkyblockPlugin plugin, SuperiorPlayer superiorPlayer
return;
}

boolean isTargetOnline = targetPlayer.isOnline();

java.util.Locale locale = superiorPlayer.getUserLocale();
IMessageComponent messageComponent;

if (island.isInvited(targetPlayer)) {
island.revokeInvite(targetPlayer);
messageComponent = Message.REVOKE_INVITE_ANNOUNCEMENT.getComponent(locale);
if (targetPlayer.isOnline())
if (isTargetOnline)
Message.GOT_REVOKED.send(targetPlayer, superiorPlayer.getName());
} else {
if (island.getTeamLimit() >= 0 && island.getIslandMembers(true).size() >= island.getTeamLimit()) {
Expand All @@ -103,16 +101,8 @@ public void execute(SuperiorSkyblockPlugin plugin, SuperiorPlayer superiorPlayer
island.inviteMember(targetPlayer);
messageComponent = Message.INVITE_ANNOUNCEMENT.getComponent(locale);

java.util.Locale targetLocal = targetPlayer.getUserLocale();
Player target = targetPlayer.asPlayer();

if (target != null && !Message.GOT_INVITE.isEmpty(targetLocal)) {
TextComponent textComponent = new TextComponent(Message.GOT_INVITE.getMessage(targetLocal, superiorPlayer.getName()));
if (!Message.GOT_INVITE_TOOLTIP.isEmpty(targetLocal))
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(Message.GOT_INVITE_TOOLTIP.getMessage(targetLocal))}));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + plugin.getCommands().getLabel() + " accept " + superiorPlayer.getName()));
target.spigot().sendMessage(textComponent);
}
if (isTargetOnline)
Message.GOT_INVITE.send(targetPlayer, superiorPlayer.getName());
}

if (messageComponent != null)
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/com/bgsoftware/superiorskyblock/lang/Message.java
Expand Up @@ -6,10 +6,15 @@
import com.bgsoftware.superiorskyblock.api.service.message.IMessageComponent;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.formatting.Formatters;
import com.bgsoftware.superiorskyblock.lang.component.impl.ComplexMessageComponent;
import com.bgsoftware.superiorskyblock.structure.AutoRemovalCollection;
import com.bgsoftware.superiorskyblock.utils.StringUtils;
import com.bgsoftware.superiorskyblock.utils.debug.PluginDebugger;
import com.bgsoftware.superiorskyblock.utils.events.EventResult;
import net.md_5.bungee.api.chat.BaseComponent;
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 org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -352,7 +357,35 @@ public enum Message {
GOT_BANNED,
GOT_DEMOTED,
GOT_EXPELLED,
GOT_INVITE,
GOT_INVITE {
@Override
public void send(CommandSender sender, Locale locale, Object... args) {
if (!(sender instanceof Player)) {
super.send(sender, locale, args);
} else {
String message = getMessage(locale);

if (message == null)
return;

BaseComponent[] baseComponents = TextComponent.fromLegacyText(message);
if (!GOT_INVITE_TOOLTIP.isEmpty(locale)) {
for (BaseComponent baseComponent : baseComponents)
baseComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(GOT_INVITE_TOOLTIP.getMessage(locale))}));
}

for (BaseComponent baseComponent : baseComponents)
baseComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + plugin.getCommands().getLabel() + " accept " + args[0]));

IMessageComponent messageComponent = ComplexMessageComponent.of(baseComponents);
if (messageComponent != null) {
EventResult<IMessageComponent> eventResult = plugin.getEventsBus().callSendMessageEvent(sender, name(), messageComponent, args);
if (!eventResult.isCancelled())
eventResult.getResult().sendMessage(sender, args);
}
}
}
},
GOT_INVITE_TOOLTIP,
GOT_KICKED,
GOT_PROMOTED,
Expand Down
Expand Up @@ -28,9 +28,6 @@
import com.bgsoftware.superiorskyblock.utils.logic.PlayersLogic;
import com.bgsoftware.superiorskyblock.utils.logic.PortalsLogic;
import com.bgsoftware.superiorskyblock.utils.teleport.TeleportUtils;
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 org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -161,16 +158,11 @@ public void onPlayerJoin(PlayerJoinEvent e) {
}

Executor.async(() -> superiorPlayer.runIfOnline(player -> {
java.util.Locale locale = superiorPlayer.getUserLocale();
Locale locale = superiorPlayer.getUserLocale();
if (!Message.GOT_INVITE.isEmpty(locale)) {
for (Island _island : plugin.getGrid().getIslands()) {
if (_island.isInvited(superiorPlayer)) {
TextComponent textComponent = new TextComponent(Message.GOT_INVITE.getMessage(locale, _island.getOwner().getName()));
if (!Message.GOT_INVITE_TOOLTIP.isEmpty(locale))
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{new TextComponent(Message.GOT_INVITE_TOOLTIP.getMessage(locale))}));
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is accept " + _island.getOwner().getName()));
player.spigot().sendMessage(textComponent);
}
if (_island.isInvited(superiorPlayer))
Message.GOT_INVITE.send(superiorPlayer, _island.getOwner().getName());
}
}
}), 40L);
Expand Down Expand Up @@ -536,7 +528,7 @@ public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
String[] message = e.getMessage().toLowerCase(Locale.ENGLISH).split(" ");

String commandLabel = message[0].toCharArray()[0] == '/' ? message[0].substring(1) : message[0];

if (island != null && !island.isSpawn() && island.isVisitor(superiorPlayer, true) &&
plugin.getSettings().getBlockedVisitorsCommands().stream().anyMatch(commandLabel::contains)) {
e.setCancelled(true);
Expand Down

0 comments on commit 7b2edff

Please sign in to comment.