Add plain broadcast

This commit is contained in:
Ghoti 2021-10-02 14:59:26 -05:00
parent 1abdd0ac7f
commit fb194e4a8e
10 changed files with 262 additions and 37 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
<repositories>
<repository>
<id>spigot-repo</id>

View File

@ -36,6 +36,9 @@ import com.fpghoti.fpchatx.command.commands.LeaveCommand;
import com.fpghoti.fpchatx.command.commands.ChannelsCommand;
import com.fpghoti.fpchatx.command.commands.CreateCommand;
import com.fpghoti.fpchatx.command.commands.MessageCommand;
import com.fpghoti.fpchatx.command.commands.PlainBroadcastCommand;
import com.fpghoti.fpchatx.command.commands.PlainBroadcastPlayerCommand;
import com.fpghoti.fpchatx.command.commands.PlainBroadcastStaffCommand;
import com.fpghoti.fpchatx.command.commands.PrefixCommand;
import com.fpghoti.fpchatx.command.commands.ReloadCommand;
import com.fpghoti.fpchatx.command.commands.ReplyCommand;
@ -176,6 +179,9 @@ public class FPChat extends JavaPlugin {
Commands.register(new RevokeBadgeCommand(this));
Commands.register(new GiveBadgeCommand(this));
Commands.register(new PrefixCommand(this));
Commands.register(new PlainBroadcastCommand(this));
Commands.register(new PlainBroadcastPlayerCommand(this));
Commands.register(new PlainBroadcastStaffCommand(this));
}
public MainConfig getMainConfig() {

View File

@ -0,0 +1,71 @@
package com.fpghoti.fpchatx.command.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.chat.BubbleCode;
import com.fpghoti.fpchatx.chat.HexColor;
import com.fpghoti.fpchatx.command.Commands;
import com.fpghoti.fpchatx.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer;
public class PlainBroadcastCommand extends Commands {
public PlainBroadcastCommand(FPChat plugin) {
super(plugin);
name = "Plain Broadcast";
description = "Sends a raw text broadcast to all players";
syntax = ChatColor.GRAY + "/plainbroadcast " + ChatColor.GOLD + "<message>";
minArgs = 0;
maxArgs = 100000;
labels.add("plainbroadcast");
labels.add("fpc plainbroadcast");
labels.add("fpchat plainbroadcast");
labels.add("ch plainbroadcast");
labels.add("pbc");
labels.add("fpc pbc");
labels.add("fpchat pbc");
labels.add("ch pbc");
labels.add("gbc");
labels.add("fpc gbc");
labels.add("fpchat gbc");
labels.add("ch gbc");
}
@Override
public void execute(CommandSender sender, String[] args) {
if(sender instanceof Player) {
FPlayer p = FPlayer.getPlayer((Player)sender);
if(!Permission.canPlainBroadcast(p)) {
FPlayer.errMsg(p, Permission.noPerm);
return;
}
}
String msg = "";
if(args.length > 0) {
msg = args[0];
}
if(args.length > 1) {
for(int i = 1; i < args.length; i++) {
msg = msg + " " + args[i];
}
}
msg = BubbleCode.bubblecode(true, ChatColor.translateAlternateColorCodes('&', HexColor.formatHex(msg)));
for(FPlayer p : FPlayer.getPlayers()) {
p.sendMessage(msg);
}
plugin.log(Level.INFO, "Plain Broadcast: " + msg);
}
}

View File

@ -0,0 +1,82 @@
package com.fpghoti.fpchatx.command.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.chat.BubbleCode;
import com.fpghoti.fpchatx.chat.HexColor;
import com.fpghoti.fpchatx.command.Commands;
import com.fpghoti.fpchatx.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer;
public class PlainBroadcastPlayerCommand extends Commands {
public PlainBroadcastPlayerCommand(FPChat plugin) {
super(plugin);
name = "Plain Broadcast Player";
description = "Sends a raw text broadcast to specified player";
syntax = ChatColor.GRAY + "/plainbroadcastplayer " + ChatColor.GOLD + "<Player> <message>";
minArgs = 1;
maxArgs = 100000;
labels.add("plainbroadcast player");
labels.add("fpc plainbroadcastplayer");
labels.add("fpchat plainbroadcastplayer");
labels.add("ch plainbroadcastplayer");
labels.add("pbcp");
labels.add("fpc pbcp");
labels.add("fpchat pbcp");
labels.add("ch pbcp");
labels.add("gbcp");
labels.add("fpc gbcp");
labels.add("fpchat gbcp");
labels.add("ch gbcp");
}
@Override
public void execute(CommandSender sender, String[] args) {
if(sender instanceof Player) {
FPlayer p = FPlayer.getPlayer((Player)sender);
if(!Permission.canPlainBroadcast(p)) {
FPlayer.errMsg(p, Permission.noPerm);
return;
}
}
String msg = "";
if(args.length > 1) {
msg = args[1];
}
if(args.length > 2) {
for(int i = 2; i < args.length; i++) {
msg = msg + " " + args[i];
}
}
msg = BubbleCode.bubblecode(true, ChatColor.translateAlternateColorCodes('&', HexColor.formatHex(msg)));
for(FPlayer p : FPlayer.getPlayers()) {
if(p.getName().toLowerCase().equals(args[0].toLowerCase())) {
p.sendMessage(msg);
plugin.log(Level.INFO, "Plain Broadcast to " + p.getName() + ": "+ msg);
return;
}
}
if(sender instanceof Player) {
FPlayer p = FPlayer.getPlayer((Player)sender);
FPlayer.errMsg(p, args[0] + " is not an online player");
}else {
plugin.log(Level.INFO, args[0] + " is not an online player");
}
}
}

View File

@ -0,0 +1,73 @@
package com.fpghoti.fpchatx.command.commands;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.fpghoti.fpchatx.FPChat;
import com.fpghoti.fpchatx.chat.BubbleCode;
import com.fpghoti.fpchatx.chat.HexColor;
import com.fpghoti.fpchatx.command.Commands;
import com.fpghoti.fpchatx.permission.Permission;
import com.fpghoti.fpchatx.player.FPlayer;
public class PlainBroadcastStaffCommand extends Commands {
public PlainBroadcastStaffCommand(FPChat plugin) {
super(plugin);
name = "Plain Broadcast Staff";
description = "Sends a raw text broadcast to all players with permissions fpchat.playerbroadcast.hearstaff and gbc.staff";
syntax = ChatColor.GRAY + "/plainbroadcaststaff " + ChatColor.GOLD + "<message>";
minArgs = 0;
maxArgs = 100000;
labels.add("plainbroadcaststaff");
labels.add("fpc plainbroadcaststaff");
labels.add("fpchat plainbroadcaststaff");
labels.add("ch plainbroadcaststaff");
labels.add("pbcs");
labels.add("fpc pbcs");
labels.add("fpchat pbcs");
labels.add("ch pbcs");
labels.add("gbcs");
labels.add("fpc gbcs");
labels.add("fpchat gbcs");
labels.add("ch gbcs");
}
@Override
public void execute(CommandSender sender, String[] args) {
if(sender instanceof Player) {
FPlayer p = FPlayer.getPlayer((Player)sender);
if(!Permission.canPlainBroadcast(p)) {
FPlayer.errMsg(p, Permission.noPerm);
return;
}
}
String msg = "";
if(args.length > 0) {
msg = args[0];
}
if(args.length > 1) {
for(int i = 1; i < args.length; i++) {
msg = msg + " " + args[i];
}
}
msg = BubbleCode.bubblecode(true, ChatColor.translateAlternateColorCodes('&', HexColor.formatHex(msg)));
for(FPlayer p : FPlayer.getPlayers()) {
if(Permission.canHearPlainStaffBroadcast(p)) {
p.sendMessage(msg);
}
}
plugin.log(Level.INFO, "Plain Broadcast Staff: " + msg);
}
}

View File

@ -20,26 +20,6 @@ public class PlayerListener implements Listener {
private boolean enabled = true;
// @EventHandler (priority = EventPriority.HIGH)
// public void onPlayerChat(AsyncPlayerChatEvent event) {
// if(enabled) {
// if (event.isCancelled()) {
// return;
// }
// Player sender = event.getPlayer();
// FPlayer p = FPlayer.getPlayer(sender);
// if(p.toTalk() && p.getTalkChannel() != null) {
// p.setTalk(false);
// ChatChannel c = p.getTalkChannel();
// p.setTalkChannel(null);
// p.chat(c, event.getMessage());
// }else {
// p.chat(event.getMessage());
// }
// event.setCancelled(true);
// }
// }
@EventHandler (priority = EventPriority.HIGH)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if(enabled) {

View File

@ -275,4 +275,20 @@ public class Permission {
return false;
}
public static boolean canPlainBroadcast(FPlayer p) {
return p.hasPermission("fpchat.plainbroadcast") || p.hasPermission("fpchat.plainbroadcast.*");
}
public static boolean canPlainPlayerBroadcast(FPlayer p) {
return p.hasPermission("fpchat.plainbroadcast.player") || p.hasPermission("fpchat.plainbroadcast.*");
}
public static boolean canPlainStaffBroadcast(FPlayer p) {
return p.hasPermission("fpchat.plainbroadcast.staff") || p.hasPermission("fpchat.plainbroadcast.*");
}
public static boolean canHearPlainStaffBroadcast(FPlayer p) {
return p.hasPermission("fpchat.plainbroadcast.hearstaff") || p.hasPermission("fpchat.plainbroadcast.*");
}
}

View File

@ -441,21 +441,6 @@ public class FPlayer {
channel.sendMessage(formatChat(channel,msg), this);
}
// public void chat(String msg) {
// if(toShout) {
// toShout = false;
// ChatChannel.getShout().sendMessage(formatChat(ChatChannel.getShout(),msg), this);
// if(FPChat.getPlugin().getMainConfig().shoutCooldownEnabled()) {
// shoutCooldown = FPChat.getPlugin().getMainConfig().getShoutSeconds();
// }
// }else if(tempspeak) {
// getPrimaryTempChannel().sendMessage(formatChat(getPrimaryTempChannel(),msg), this);
// }else {
// getPrimaryChannel().sendMessage(formatChat(msg), this);
// }
// }
public void chat(String msg) {
if(toShout) {
toShout = false;

View File

@ -69,4 +69,16 @@ commands:
aliases: [tk]
description: Set main channel
usage: /<command> channel
plainbroadcast:
aliases: [pbc,gbc]
description: Sends a plain broadcast to all players.
usage: /<command> message
plainbroadcastplayer:
aliases: [pbcp,gbcp]
description: Sends a plain broadcast to a player.
usage: /<command> player message
plainbroadcaststaff:
aliases: [pbcs,gbcs]
description: Sends a plain broadcast to a player with permissions fpchat.playerbroadcast.hearstaff and gbc.staff.
usage: /<command> message