Made broadcasts and Fs better
- Made *many* messages sent to each player a broadcast message instead - Removed FCount and PressedF, added the Fs list instead - Added support for *all* CommandSenders for F - Inlined PluginMain.GetPlayers()
This commit is contained in:
parent
4311a567c5
commit
5e20689dc1
7 changed files with 38 additions and 69 deletions
|
@ -1,6 +1,6 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public class AnnouncerThread {
|
public class AnnouncerThread {
|
||||||
private static int AnnounceMessageIndex = 0;
|
private static int AnnounceMessageIndex = 0;
|
||||||
|
@ -13,9 +13,7 @@ public class AnnouncerThread {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
||||||
for (Player player : PluginMain.GetPlayers())
|
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
|
||||||
player.sendMessage(PluginMain.AnnounceMessages
|
|
||||||
.get(AnnounceMessageIndex));
|
|
||||||
AnnounceMessageIndex++;
|
AnnounceMessageIndex++;
|
||||||
if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size())
|
if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size())
|
||||||
AnnounceMessageIndex = 0;
|
AnnounceMessageIndex = 0;
|
||||||
|
|
|
@ -73,7 +73,6 @@ public class ChatPlayer extends TBMCPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean RPMode = true;
|
public boolean RPMode = true;
|
||||||
public boolean PressedF;
|
|
||||||
public Location SavedLocation;
|
public Location SavedLocation;
|
||||||
public boolean Working;
|
public boolean Working;
|
||||||
// public int Tables = 10;
|
// public int Tables = 10;
|
||||||
|
|
|
@ -56,18 +56,12 @@ public class ChatProcessing {
|
||||||
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||||
|
PlayerListener.Fs.add(sender);
|
||||||
|
|
||||||
ChatPlayer mp = null;
|
ChatPlayer mp = null;
|
||||||
if (player != null) {
|
if (player != null)
|
||||||
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
|
mp = TBMCPlayer.getPlayer(player).asPluginPlayer(ChatPlayer.class);
|
||||||
if (message.equalsIgnoreCase("F")) {
|
|
||||||
if (!mp.PressedF && PlayerListener.ActiveF) {
|
|
||||||
PlayerListener.FCount++;
|
|
||||||
mp.PressedF = true;
|
|
||||||
if (PlayerListener.FPlayer != null && PlayerListener.FPlayer.getFCount() < Integer.MAX_VALUE - 1)
|
|
||||||
PlayerListener.FPlayer.setFCount(PlayerListener.FPlayer.getFCount() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String msg = message.toLowerCase();
|
String msg = message.toLowerCase();
|
||||||
if (msg.contains("lol")) {
|
if (msg.contains("lol")) {
|
||||||
|
@ -113,34 +107,30 @@ public class ChatProcessing {
|
||||||
// URLs + Rainbow text
|
// URLs + Rainbow text
|
||||||
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1")
|
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1")
|
||||||
.build());
|
.build());
|
||||||
if (PluginMain.GetPlayers().size() > 0) {
|
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||||
StringBuilder namesb = new StringBuilder();
|
StringBuilder namesb = new StringBuilder();
|
||||||
namesb.append("(?i)(");
|
namesb.append("(?i)(");
|
||||||
for (Player p : PluginMain.GetPlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
namesb.append(p.getName()).append("|");
|
namesb.append(p.getName()).append("|");
|
||||||
namesb.deleteCharAt(namesb.length() - 1);
|
namesb.deleteCharAt(namesb.length() - 1);
|
||||||
namesb.append(")");
|
namesb.append(")");
|
||||||
StringBuilder nicksb = new StringBuilder();
|
StringBuilder nicksb = new StringBuilder();
|
||||||
nicksb.append("(?i)(");
|
nicksb.append("(?i)(");
|
||||||
{
|
{
|
||||||
final int size = PluginMain.GetPlayers().size();
|
final int size = Bukkit.getOnlinePlayers().size();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Player p : PluginMain.GetPlayers())
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
{
|
|
||||||
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
||||||
if (nick != null)
|
if (nick != null) {
|
||||||
{
|
nicksb.append(nick);
|
||||||
nicksb.append(nick);
|
if (index < size - 1) {
|
||||||
if (index < size - 1)
|
nicksb.append("|");
|
||||||
{
|
}
|
||||||
nicksb.append("|");
|
}
|
||||||
}
|
index++;
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
nicksb.append(")");
|
nicksb.append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
formatters
|
formatters
|
||||||
.add(new ChatFormatterBuilder().setRegex(Pattern.compile("null")).setColor(Color.DarkRed).build()); // Properly added a bug as a feature
|
.add(new ChatFormatterBuilder().setRegex(Pattern.compile("null")).setColor(Color.DarkRed).build()); // Properly added a bug as a feature
|
||||||
|
@ -273,7 +263,7 @@ public class ChatProcessing {
|
||||||
sender.sendMessage("§cYou are not a player!");
|
sender.sendMessage("§cYou are not a player!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
try {
|
try {
|
||||||
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
|
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
|
||||||
if (resident != null && !resident.getName().equals(player.getName())
|
if (resident != null && !resident.getName().equals(player.getName())
|
||||||
|
@ -304,7 +294,7 @@ public class ChatProcessing {
|
||||||
index = PluginMain.Instance.Towns.size() - 1;
|
index = PluginMain.Instance.Towns.size() - 1;
|
||||||
}
|
}
|
||||||
Objective obj = PluginMain.SB.getObjective("town");
|
Objective obj = PluginMain.SB.getObjective("town");
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
try {
|
try {
|
||||||
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
||||||
obj.getScore(p.getName()).setScore(index);
|
obj.getScore(p.getName()).setScore(index);
|
||||||
|
@ -344,7 +334,7 @@ public class ChatProcessing {
|
||||||
index = PluginMain.Instance.Nations.size() - 1;
|
index = PluginMain.Instance.Nations.size() - 1;
|
||||||
}
|
}
|
||||||
Objective obj = PluginMain.SB.getObjective("nation");
|
Objective obj = PluginMain.SB.getObjective("nation");
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
try {
|
try {
|
||||||
if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
||||||
obj.getScore(p.getName()).setScore(index);
|
obj.getScore(p.getName()).setScore(index);
|
||||||
|
@ -361,7 +351,7 @@ public class ChatProcessing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Objective obj = PluginMain.SB.getObjective("admin");
|
Objective obj = PluginMain.SB.getObjective("admin");
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (p.isOp())
|
if (p.isOp())
|
||||||
obj.getScore(p.getName()).setScore(1);
|
obj.getScore(p.getName()).setScore(1);
|
||||||
else
|
else
|
||||||
|
@ -375,7 +365,7 @@ public class ChatProcessing {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Objective obj = PluginMain.SB.getObjective("mod");
|
Objective obj = PluginMain.SB.getObjective("mod");
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (PluginMain.permission.playerInGroup(p, "mod"))
|
if (PluginMain.permission.playerInGroup(p, "mod"))
|
||||||
obj.getScore(p.getName()).setScore(1);
|
obj.getScore(p.getName()).setScore(1);
|
||||||
else
|
else
|
||||||
|
|
|
@ -37,7 +37,6 @@ import java.net.URLConnection;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -253,10 +252,6 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
|
p.sendMessage("§9A Reddit user commented your name. Is that you?§r §6Type /u accept or /u ignore§r");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers() {
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
||||||
public static int AnnounceTime = 15 * 60 * 1000;
|
public static int AnnounceTime = 15 * 60 * 1000;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
|
||||||
public final class UnlolCommand extends TBMCCommandBase {
|
public final class UnlolCommand extends TBMCCommandBase {
|
||||||
|
@ -31,9 +30,7 @@ public final class UnlolCommand extends TBMCCommandBase {
|
||||||
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
|
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
|
||||||
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
||||||
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName());
|
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName());
|
||||||
for (Player pl : PluginMain.GetPlayers())
|
Bukkit.broadcastMessage(msg);
|
||||||
pl.sendMessage(msg);
|
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(msg);
|
|
||||||
Lastlol = null;
|
Lastlol = null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -4,7 +4,6 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
|
||||||
import buttondevteam.lib.TBMCYEEHAWEvent;
|
import buttondevteam.lib.TBMCYEEHAWEvent;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
|
||||||
|
@ -19,12 +18,11 @@ public class YeehawCommand extends TBMCCommandBase {
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||||
final String message = "§b* "
|
final String message = "§b* "
|
||||||
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
|
+ (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs.";
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f);
|
p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f);
|
||||||
p.sendMessage(message);
|
|
||||||
} // Even a cmdblock could yeehaw in theory
|
} // Even a cmdblock could yeehaw in theory
|
||||||
// Or anyone from Discord
|
// Or anyone from Discord
|
||||||
Bukkit.getConsoleSender().sendMessage(message);
|
Bukkit.broadcastMessage(message);
|
||||||
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.chat.listener;
|
package buttondevteam.chat.listener;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
@ -10,6 +11,7 @@ import com.palmergames.bukkit.towny.Towny;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -111,8 +113,7 @@ public class PlayerListener implements Listener {
|
||||||
if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) {
|
if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
String message = event.getMessage().substring(index + 1);
|
String message = event.getMessage().substring(index + 1);
|
||||||
for (Player p : PluginMain.GetPlayers())
|
Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
|
||||||
p.sendMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,10 +168,7 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||||
for (Player pl : PluginMain.GetPlayers())
|
Bukkit.broadcastMessage(
|
||||||
pl.sendMessage(
|
|
||||||
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
|
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(
|
|
||||||
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
|
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -198,10 +196,10 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean ActiveF = false;
|
public static boolean ActiveF = false;
|
||||||
public static int FCount = 0;
|
|
||||||
public static ChatPlayer FPlayer = null;
|
public static ChatPlayer FPlayer = null;
|
||||||
private Timer Ftimer;
|
private Timer Ftimer;
|
||||||
public static int AlphaDeaths;
|
public static int AlphaDeaths;
|
||||||
|
public static ArrayList<CommandSender> Fs = new ArrayList<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||||
|
@ -212,24 +210,21 @@ public class PlayerListener implements Listener {
|
||||||
if (Ftimer != null)
|
if (Ftimer != null)
|
||||||
Ftimer.cancel();
|
Ftimer.cancel();
|
||||||
ActiveF = true;
|
ActiveF = true;
|
||||||
FCount = 0;
|
Fs.clear();
|
||||||
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
|
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
|
||||||
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
|
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
|
||||||
ChatPlayer mp = TBMCPlayer.getPlayerAs(p.getUniqueId(), ChatPlayer.class);
|
|
||||||
mp.PressedF = false;
|
|
||||||
p.sendMessage("§bPress F to pay respects.§r");
|
|
||||||
}
|
|
||||||
Ftimer = new Timer();
|
Ftimer = new Timer();
|
||||||
TimerTask tt = new TimerTask() {
|
TimerTask tt = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ActiveF) {
|
if (ActiveF) {
|
||||||
ActiveF = false;
|
ActiveF = false;
|
||||||
for (Player p : PluginMain.GetPlayers()) {
|
if (FPlayer != null && FPlayer.getFCount() < Integer.MAX_VALUE - 1)
|
||||||
p.sendMessage("§b" + FCount + " " + (FCount == 1 ? "person" : "people")
|
FPlayer.setFCount(FPlayer.getFCount() + Fs.size());
|
||||||
+ " paid their respects.§r");
|
Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people")
|
||||||
}
|
+ " paid their respects.§r");
|
||||||
|
Fs.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -315,10 +310,7 @@ public class PlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||||
for (Player pl : PluginMain.GetPlayers())
|
Bukkit.broadcastMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
||||||
pl.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
|
||||||
Bukkit.getServer().getConsoleSender()
|
|
||||||
.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
|
||||||
event.setCommand("dontrunthiscmd");
|
event.setCommand("dontrunthiscmd");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue