mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Add toggle command and feature
This commit is contained in:
1 parent
225bd6e08e
commit
5e30aed924
5 files changed
+82
-4
No files matched your search
@@ -5,6 +5,7 @@ import co.aikar.commands.ConditionFailedException;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.draycia.simplechat.channels.SimpleChatChannel;
|
||||
import net.draycia.simplechat.commands.ChannelCommand;
|
||||
import net.draycia.simplechat.commands.ToggleCommand;
|
||||
import net.draycia.simplechat.listeners.PlayerChatListener;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -135,6 +136,7 @@ public final class SimpleChat extends JavaPlugin {
|
||||
}
|
||||
|
||||
manager.registerCommand(new ChannelCommand(this));
|
||||
manager.registerCommand(new ToggleCommand(this));
|
||||
|
||||
setupListeners();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,18 @@ public abstract class ChatChannel {
|
||||
*/
|
||||
public abstract String getSwitchMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel off.
|
||||
*/
|
||||
|
||||
public abstract String getToggleOffMessage();
|
||||
|
||||
/**
|
||||
* @return The message to be send to the player when toggling this channel on.
|
||||
*/
|
||||
|
||||
public abstract String getToggleOnMessage();
|
||||
|
||||
/**
|
||||
* @return If this channel is Towny's town chat.
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,8 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
private String name;
|
||||
private double distance;
|
||||
private String switchMessage;
|
||||
private String toggleOffMessage;
|
||||
private String toggleOnMessage;
|
||||
|
||||
// Plugin hooks
|
||||
private boolean isTownChat;
|
||||
@@ -229,9 +231,9 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (!simpleChat.hasToggledOn(player, this)) {
|
||||
//
|
||||
// }
|
||||
if (simpleChat.playerHasChannelMuted(target, this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -291,6 +293,16 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
return switchMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToggleOffMessage() {
|
||||
return toggleOffMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToggleOnMessage() {
|
||||
return toggleOnMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTownChat() {
|
||||
return isTownChat;
|
||||
@@ -327,6 +339,8 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
private String name;
|
||||
private double distance = 0;
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
private boolean isTownChat = false;
|
||||
private boolean isNationChat = false;
|
||||
private boolean isAllianceChat = false;
|
||||
@@ -402,6 +416,18 @@ public class SimpleChatChannel extends ChatChannel {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setToggleOffMessage(String toggleOffMessage) {
|
||||
this.toggleOffMessage = toggleOffMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setToggleOnMessage(String toggleOnMessage) {
|
||||
this.toggleOnMessage = toggleOnMessage;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setIsTownChat(boolean isTownChat) {
|
||||
this.isTownChat = isTownChat;
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.draycia.simplechat.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import me.minidigger.minimessage.text.MiniMessageParser;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.channels.ChatChannel;
|
||||
import net.kyori.text.adapter.bukkit.TextAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandAlias("tch|togglec|togglechannel|toggle")
|
||||
public class ToggleCommand extends BaseCommand {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
public ToggleCommand(SimpleChat simpleChat) {
|
||||
this.simpleChat = simpleChat;
|
||||
}
|
||||
|
||||
@Default
|
||||
@CommandCompletion("@chatchannel")
|
||||
public void baseCommand(Player player, @Conditions("canuse:true") ChatChannel channel) {
|
||||
String message;
|
||||
|
||||
if (simpleChat.togglePlayerChannelMute(player, channel)) {
|
||||
message = channel.getToggleOnMessage();
|
||||
} else {
|
||||
message = channel.getToggleOffMessage();
|
||||
}
|
||||
|
||||
message = MiniMessageParser.handlePlaceholders(message, "color", channel.getColor().toString());
|
||||
|
||||
TextAdapter.sendMessage(player, MiniMessageParser.parseFormat(message, "channel", channel.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user