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;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class AnnouncerThread {
|
||||
private static int AnnounceMessageIndex = 0;
|
||||
|
@ -13,9 +13,7 @@ public class AnnouncerThread {
|
|||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (PluginMain.AnnounceMessages.size() > AnnounceMessageIndex) {
|
||||
for (Player player : PluginMain.GetPlayers())
|
||||
player.sendMessage(PluginMain.AnnounceMessages
|
||||
.get(AnnounceMessageIndex));
|
||||
Bukkit.broadcastMessage(PluginMain.AnnounceMessages.get(AnnounceMessageIndex));
|
||||
AnnounceMessageIndex++;
|
||||
if (AnnounceMessageIndex == PluginMain.AnnounceMessages.size())
|
||||
AnnounceMessageIndex = 0;
|
||||
|
|
|
@ -73,7 +73,6 @@ public class ChatPlayer extends TBMCPlayer {
|
|||
}
|
||||
|
||||
public boolean RPMode = true;
|
||||
public boolean PressedF;
|
||||
public Location SavedLocation;
|
||||
public boolean Working;
|
||||
// public int Tables = 10;
|
||||
|
|
|
@ -56,18 +56,12 @@ public class ChatProcessing {
|
|||
if (player != null && PluginMain.essentials.getUser(player).isMuted())
|
||||
return true;
|
||||
|
||||
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
|
||||
PlayerListener.Fs.add(sender);
|
||||
|
||||
ChatPlayer mp = null;
|
||||
if (player != null) {
|
||||
if (player != null)
|
||||
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();
|
||||
if (msg.contains("lol")) {
|
||||
|
@ -113,34 +107,30 @@ public class ChatProcessing {
|
|||
// URLs + Rainbow text
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(Format.Underlined).setOpenlink("$1")
|
||||
.build());
|
||||
if (PluginMain.GetPlayers().size() > 0) {
|
||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||
StringBuilder namesb = new StringBuilder();
|
||||
namesb.append("(?i)(");
|
||||
for (Player p : PluginMain.GetPlayers())
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
namesb.append(p.getName()).append("|");
|
||||
namesb.deleteCharAt(namesb.length() - 1);
|
||||
namesb.append(")");
|
||||
StringBuilder nicksb = new StringBuilder();
|
||||
nicksb.append("(?i)(");
|
||||
{
|
||||
final int size = PluginMain.GetPlayers().size();
|
||||
final int size = Bukkit.getOnlinePlayers().size();
|
||||
int index = 0;
|
||||
for (Player p : PluginMain.GetPlayers())
|
||||
{
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
|
||||
if (nick != null)
|
||||
{
|
||||
nicksb.append(nick);
|
||||
if (index < size - 1)
|
||||
{
|
||||
nicksb.append("|");
|
||||
}
|
||||
}
|
||||
index++;
|
||||
if (nick != null) {
|
||||
nicksb.append(nick);
|
||||
if (index < size - 1) {
|
||||
nicksb.append("|");
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
nicksb.append(")");
|
||||
}
|
||||
|
||||
|
||||
formatters
|
||||
.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!");
|
||||
return true;
|
||||
}
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase());
|
||||
if (resident != null && !resident.getName().equals(player.getName())
|
||||
|
@ -304,7 +294,7 @@ public class ChatProcessing {
|
|||
index = PluginMain.Instance.Towns.size() - 1;
|
||||
}
|
||||
Objective obj = PluginMain.SB.getObjective("town");
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
||||
obj.getScore(p.getName()).setScore(index);
|
||||
|
@ -344,7 +334,7 @@ public class ChatProcessing {
|
|||
index = PluginMain.Instance.Nations.size() - 1;
|
||||
}
|
||||
Objective obj = PluginMain.SB.getObjective("nation");
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName())))
|
||||
obj.getScore(p.getName()).setScore(index);
|
||||
|
@ -361,7 +351,7 @@ public class ChatProcessing {
|
|||
return true;
|
||||
}
|
||||
Objective obj = PluginMain.SB.getObjective("admin");
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.isOp())
|
||||
obj.getScore(p.getName()).setScore(1);
|
||||
else
|
||||
|
@ -375,7 +365,7 @@ public class ChatProcessing {
|
|||
return true;
|
||||
}
|
||||
Objective obj = PluginMain.SB.getObjective("mod");
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (PluginMain.permission.playerInGroup(p, "mod"))
|
||||
obj.getScore(p.getName()).setScore(1);
|
||||
else
|
||||
|
|
|
@ -37,7 +37,6 @@ import java.net.URLConnection;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
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");
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> GetPlayers() {
|
||||
return Instance.getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static ArrayList<String> AnnounceMessages = new ArrayList<>();
|
||||
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.PotionEffectType;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.chat.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())
|
||||
+ (Lastlolornot ? " unlolled " : " unlaughed ")
|
||||
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName());
|
||||
for (Player pl : PluginMain.GetPlayers())
|
||||
pl.sendMessage(msg);
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(msg);
|
||||
Bukkit.broadcastMessage(msg);
|
||||
Lastlol = null;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.TBMCYEEHAWEvent;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
|
||||
|
@ -19,12 +18,11 @@ public class YeehawCommand extends TBMCCommandBase {
|
|||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
final String message = "§b* "
|
||||
+ (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.sendMessage(message);
|
||||
} // Even a cmdblock could yeehaw in theory
|
||||
// Or anyone from Discord
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
Bukkit.broadcastMessage(message);
|
||||
Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.chat.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
|
@ -10,6 +11,7 @@ import com.palmergames.bukkit.towny.Towny;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
@ -111,8 +113,7 @@ public class PlayerListener implements Listener {
|
|||
if (!PluginMain.essentials.getUser(event.getPlayer()).isMuted()) {
|
||||
event.setCancelled(true);
|
||||
String message = event.getMessage().substring(index + 1);
|
||||
for (Player p : PluginMain.GetPlayers())
|
||||
p.sendMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
|
||||
Bukkit.broadcastMessage(String.format("* %s %s", event.getPlayer().getDisplayName(), message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,10 +168,7 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
if (target != null) {
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||
for (Player pl : PluginMain.GetPlayers())
|
||||
pl.sendMessage(
|
||||
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(
|
||||
Bukkit.broadcastMessage(
|
||||
event.getPlayer().getDisplayName() + " un" + s + "'d " + target.getDisplayName());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -198,10 +196,10 @@ public class PlayerListener implements Listener {
|
|||
}
|
||||
|
||||
public static boolean ActiveF = false;
|
||||
public static int FCount = 0;
|
||||
public static ChatPlayer FPlayer = null;
|
||||
private Timer Ftimer;
|
||||
public static int AlphaDeaths;
|
||||
public static ArrayList<CommandSender> Fs = new ArrayList<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
|
@ -212,24 +210,21 @@ public class PlayerListener implements Listener {
|
|||
if (Ftimer != null)
|
||||
Ftimer.cancel();
|
||||
ActiveF = true;
|
||||
FCount = 0;
|
||||
Fs.clear();
|
||||
FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId()).asPluginPlayer(ChatPlayer.class);
|
||||
FPlayer.setFDeaths(FPlayer.getFDeaths() + 1);
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
ChatPlayer mp = TBMCPlayer.getPlayerAs(p.getUniqueId(), ChatPlayer.class);
|
||||
mp.PressedF = false;
|
||||
p.sendMessage("§bPress F to pay respects.§r");
|
||||
}
|
||||
Bukkit.broadcastMessage("§bPress F to pay respects.§r");
|
||||
Ftimer = new Timer();
|
||||
TimerTask tt = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ActiveF) {
|
||||
ActiveF = false;
|
||||
for (Player p : PluginMain.GetPlayers()) {
|
||||
p.sendMessage("§b" + FCount + " " + (FCount == 1 ? "person" : "people")
|
||||
+ " paid their respects.§r");
|
||||
}
|
||||
if (FPlayer != null && FPlayer.getFCount() < Integer.MAX_VALUE - 1)
|
||||
FPlayer.setFCount(FPlayer.getFCount() + Fs.size());
|
||||
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) {
|
||||
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false));
|
||||
for (Player pl : PluginMain.GetPlayers())
|
||||
pl.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
||||
Bukkit.getServer().getConsoleSender()
|
||||
.sendMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
||||
Bukkit.broadcastMessage(event.getSender().getName() + " un" + s + "'d " + target.getDisplayName());
|
||||
event.setCommand("dontrunthiscmd");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue