Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #228, implement Ranged-Chat command. #230

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/src/main/java/at/helpch/chatchat/api/user/ChatUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,20 @@ public interface ChatUser extends User {
* @param enable True to enable social spy, false to disable.
*/
void socialSpy(final boolean enable);

/**
* Checks if the user has ranged chat enabled.
* If it is enabled, they will only see messages from players within a certain range.
* Only applies to the players that have bypass ChannelUtils.BYPASS_RADIUS_CHANNEL_PERMISSION.
*
* @return True if the user has ranged chat enabled, false otherwise.
*/
boolean rangedChat();

/**
* Changes the state of the user's ranged chat.
*
* @param enable True to enable ranged chat, false to disable.
*/
void rangedChat(final boolean enable);
}
4 changes: 3 additions & 1 deletion plugin/src/main/java/at/helpch/chatchat/ChatChatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import at.helpch.chatchat.command.IgnoreListCommand;
import at.helpch.chatchat.command.MainCommand;
import at.helpch.chatchat.command.MentionToggleCommand;
import at.helpch.chatchat.command.RangedChatCommand;
import at.helpch.chatchat.command.ReloadCommand;
import at.helpch.chatchat.command.ReplyCommand;
import at.helpch.chatchat.command.SocialSpyCommand;
Expand Down Expand Up @@ -274,7 +275,8 @@ private void registerCommands() {
new MentionToggleCommand(this),
new FormatTestCommand(this),
new DumpCommand(this),
new ChatToggleCommand(this)
new ChatToggleCommand(this),
new RangedChatCommand(this)
).forEach(commandManager::registerCommand);

if (configManager.settings().privateMessagesSettings().enabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package at.helpch.chatchat.command;

import at.helpch.chatchat.ChatChatPlugin;
import at.helpch.chatchat.api.user.ChatUser;
import dev.triumphteam.cmd.bukkit.annotation.Permission;
import dev.triumphteam.cmd.core.BaseCommand;
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.Default;

@Command("rangedchat")
public class RangedChatCommand extends BaseCommand {

private static final String CHAT_TOGGLE_PERMISSION = "chatchat.rangedchat";
private final ChatChatPlugin plugin;

public RangedChatCommand(final ChatChatPlugin plugin) {
this.plugin = plugin;
}

@Default
@Permission(CHAT_TOGGLE_PERMISSION)
public void toggleRangedChat(final ChatUser sender) {
sender.rangedChat(!sender.rangedChat());

final var messageHolder = plugin.configManager().messages();
final var message = sender.rangedChat() ?
messageHolder.rangedChatEnabledSuccessfully() :
messageHolder.rangedChatDisabledSuccessfully();

sender.sendMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public final class MessagesHolder {
private Component channelNoPermissionSwitch = text("You no longer have permission to use this channel so it has been switched to the <default> channel. ", RED);
private Component channelSwitched = text("You have switched to the <channel> channel", GREEN);

private Component rangedChatEnabledSuccessfully = text("Your ranged chat has been enabled successfully!", GREEN);
private Component rangedChatDisabledSuccessfully = text("Your ranged chat has been disabled successfully!", RED);

// command related
private Component commandUnknownCommand = text("Unknown Command.", RED);
private Component commandInvalidUsage = text("Invalid usage.", RED);
Expand Down Expand Up @@ -237,4 +240,12 @@ public final class MessagesHolder {
return chatDisabled;
}

public @NotNull Component rangedChatEnabledSuccessfully() {
return rangedChatEnabledSuccessfully;
}

public @NotNull Component rangedChatDisabledSuccessfully() {
return rangedChatDisabledSuccessfully;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public PlaceholderAPIPlaceholders(@NotNull final ChatChatPlugin plugin) {
"%chatchat_channel_message_prefix%",
"%chatchat_social_spy_enabled%",
"%chatchat_private_messages_enabled%",
"%chatchat_private_messages_recipient%"
"%chatchat_private_messages_recipient%",
"%chatchat_ranged_chat_enabled%"
);
}

Expand Down Expand Up @@ -86,6 +87,8 @@ public String onRequest(final OfflinePlayer offlinePlayer, @NotNull final String
return formatBoolean(chatUser.privateMessages());
case "private_messages_recipient":
return chatUser.lastMessagedUser().map(value -> value.player().getName()).orElse("");
case "ranged_chat_enabled":
return formatBoolean(chatUser.rangedChat());
}

return null;
Expand Down
11 changes: 11 additions & 0 deletions plugin/src/main/java/at/helpch/chatchat/user/ChatUserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public ChatUserImpl(@NotNull final UUID uuid) {
private boolean channelMentions = true;
private boolean socialSpy = false;
private boolean chatEnabled = true;
private boolean rangedChat = false;
private Set<UUID> ignoredUsers = new HashSet<>();

@Override
Expand Down Expand Up @@ -150,6 +151,16 @@ public boolean chatEnabled() {
return this.chatEnabled;
}

@Override
public boolean rangedChat() {
return rangedChat;
}

@Override
public void rangedChat(final boolean enabled) {
this.rangedChat = enabled;
}

@Override
public boolean canSee(@NotNull final User target) {
if (!(target instanceof ChatUser)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ public static boolean isTargetWithinRadius(
return true;
}

if (target.hasPermission(BYPASS_RADIUS_CHANNEL_PERMISSION)) {
final ChatUser targetChatUser = (ChatUser) target;

if (target.hasPermission(BYPASS_RADIUS_CHANNEL_PERMISSION) && !targetChatUser.rangedChat()) {
return true;
}

if (radius != -1 && source instanceof ChatUser) {
final Location sourceLocation = ((ChatUser) source).player().getLocation();
final Location sourceLocation = targetChatUser.player().getLocation();
final Location targetLocation = ((ChatUser) target).player().getLocation();

final World sourceWorld = sourceLocation.getWorld();
Expand Down
Loading