Skip to content

Commit

Permalink
Add ability to send player text with hover / click effects
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperDeborah committed Dec 29, 2023
1 parent cfa80ab commit 52bcb31
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/no/runsafe/framework/api/command/ICommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface ICommandExecutor
UUID getUniqueId();
void sendMessage(String message);
void sendColouredMessage(String format, Object... params);
void sendComplexMessage(String message, String hoverText, String clickCommand);
boolean hasPermission(String permission);
boolean performCommand(String command);
@Override boolean equals(Object o);
Expand Down
2 changes: 2 additions & 0 deletions src/no/runsafe/framework/api/player/IPlayerNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface IPlayerNotification
{
void sendColouredMessage(String format, Object... params);

void sendComplexMessage(String message, String hoverText, String clickCommand);

void sendTitle(String title, String subtitle);

void resetTitle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package no.runsafe.framework.internal.extension.player;

import com.google.common.collect.ImmutableList;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import no.runsafe.framework.api.ILocation;
import no.runsafe.framework.api.IUniverse;
import no.runsafe.framework.api.IWorld;
import no.runsafe.framework.api.chunk.IChunk;
import no.runsafe.framework.api.entity.IEntity;
import no.runsafe.framework.api.hook.IPlayerExtensions;
import no.runsafe.framework.api.networking.IPacket;
import no.runsafe.framework.api.player.IPlayer;
import no.runsafe.framework.internal.InjectionPlugin;
import no.runsafe.framework.internal.wrapper.BukkitLocation;
import no.runsafe.framework.internal.wrapper.player.BukkitPlayer;
import no.runsafe.framework.minecraft.Item;
import no.runsafe.framework.minecraft.entity.RunsafeEntity;
import no.runsafe.framework.minecraft.event.player.RunsafeOperatorEvent;
import no.runsafe.framework.minecraft.inventory.RunsafePlayerInventory;
import no.runsafe.framework.minecraft.item.meta.RunsafeMeta;
Expand Down Expand Up @@ -306,6 +312,23 @@ public void sendColouredMessage(String format, Object... params)
sendMessage(ChatColour.ToMinecraft(String.format(format, params)));
}

@Override
public void sendComplexMessage(String message, String hoverText, String clickCommand)
{
if (message == null)
return;

TextComponent component = new TextComponent(ChatColour.ToMinecraft(message));

if (hoverText != null)
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColour.ToMinecraft(hoverText)).create()));

if (clickCommand != null)
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand));

player.spigot().sendMessage(component);
}

@SuppressWarnings("CastToConcreteClass")
@Override
public void throwToPoint(ILocation location)
Expand Down
20 changes: 20 additions & 0 deletions src/no/runsafe/framework/minecraft/RunsafeConsole.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package no.runsafe.framework.minecraft;

import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import no.runsafe.framework.api.log.IConsole;
import no.runsafe.framework.api.command.ICommandExecutor;
import no.runsafe.framework.internal.InjectionPlugin;
import no.runsafe.framework.internal.configuration.FrameworkConfiguration;
import no.runsafe.framework.text.ChatColour;
import org.apache.commons.lang.NotImplementedException;

import java.util.UUID;
Expand Down Expand Up @@ -45,6 +50,21 @@ public void sendColouredMessage(String format, Object... params)
output.writeColoured(format, Level.INFO, params);
}

@Override
public void sendComplexMessage(String message, String hoverText, String clickCommand)
{
if (message == null)
return;

if (hoverText != null)
message += (" Hover Text: " + hoverText);

if (clickCommand != null)
message += (" Click Command: " + clickCommand);

output.writeColoured(message, Level.INFO);
}

@Override
public boolean hasPermission(String permission)
{
Expand Down

0 comments on commit 52bcb31

Please sign in to comment.