diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 684b9dd..0e37d29 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.fpghoti FPChat - 1.1.6 + 1.1.7 src/main/java diff --git a/pom.xml b/pom.xml index 8a34b46..b64c218 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.fpghoti FPChat - 1.1.6 + 1.1.7 spigot-repo diff --git a/src/main/java/com/fpghoti/fpchatx/FPChat.java b/src/main/java/com/fpghoti/fpchatx/FPChat.java index 7410e26..a327c7a 100644 --- a/src/main/java/com/fpghoti/fpchatx/FPChat.java +++ b/src/main/java/com/fpghoti/fpchatx/FPChat.java @@ -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() { diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastCommand.java new file mode 100644 index 0000000..1c14742 --- /dev/null +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastCommand.java @@ -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 + ""; + 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); + } + +} diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastPlayerCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastPlayerCommand.java new file mode 100644 index 0000000..a3340ac --- /dev/null +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastPlayerCommand.java @@ -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 + " "; + 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"); + } + + + } + +} diff --git a/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastStaffCommand.java b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastStaffCommand.java new file mode 100644 index 0000000..e520c84 --- /dev/null +++ b/src/main/java/com/fpghoti/fpchatx/command/commands/PlainBroadcastStaffCommand.java @@ -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 + ""; + 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); + } + +} diff --git a/src/main/java/com/fpghoti/fpchatx/listener/PlayerListener.java b/src/main/java/com/fpghoti/fpchatx/listener/PlayerListener.java index 948c1e5..0b0249e 100644 --- a/src/main/java/com/fpghoti/fpchatx/listener/PlayerListener.java +++ b/src/main/java/com/fpghoti/fpchatx/listener/PlayerListener.java @@ -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) { diff --git a/src/main/java/com/fpghoti/fpchatx/permission/Permission.java b/src/main/java/com/fpghoti/fpchatx/permission/Permission.java index 7adbd4a..6e93713 100644 --- a/src/main/java/com/fpghoti/fpchatx/permission/Permission.java +++ b/src/main/java/com/fpghoti/fpchatx/permission/Permission.java @@ -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.*"); + } + } diff --git a/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java b/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java index 9a67a1c..5ff3935 100644 --- a/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java +++ b/src/main/java/com/fpghoti/fpchatx/player/FPlayer.java @@ -440,21 +440,6 @@ public class FPlayer { public void chat(ChatChannel channel, String msg) { 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) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 548d823..73d3772 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -69,4 +69,16 @@ commands: aliases: [tk] description: Set main channel usage: / channel + plainbroadcast: + aliases: [pbc,gbc] + description: Sends a plain broadcast to all players. + usage: / message + plainbroadcastplayer: + aliases: [pbcp,gbcp] + description: Sends a plain broadcast to a player. + usage: / player message + plainbroadcaststaff: + aliases: [pbcs,gbcs] + description: Sends a plain broadcast to a player with permissions fpchat.playerbroadcast.hearstaff and gbc.staff. + usage: / message