Added support for /ignore, improved unlols

This commit is contained in:
Norbi Peti 2017-08-22 01:37:54 +02:00
parent 2f83a90553
commit 1d1b3453b3
4 changed files with 45 additions and 22 deletions

View file

@ -19,11 +19,13 @@ import buttondevteam.chat.commands.UnlolCommand;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.chat.formatting.*; import buttondevteam.chat.formatting.*;
import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.lib.chat.TellrawSerializableEnum;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import lombok.val;
import buttondevteam.chat.listener.PlayerListener; import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.chat.*; import buttondevteam.lib.chat.*;
@ -90,7 +92,7 @@ public class ChatProcessing {
if (player != null && PluginMain.essentials.getUser(player).isMuted()) if (player != null && PluginMain.essentials.getUser(player).isMuted())
return true; return true;
doFunStuff(sender, message); doFunStuff(sender, e, message);
ChatPlayer mp = null; ChatPlayer mp = null;
if (player != null) if (player != null)
@ -132,6 +134,8 @@ public class ChatProcessing {
Objective obj = PluginMain.SB.getObjective(channel.ID); Objective obj = PluginMain.SB.getObjective(channel.ID);
int score = -1; int score = -1;
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player)))
continue;
final int mcScore = VanillaUtils.getMCScoreIfChatOn(p, e); final int mcScore = VanillaUtils.getMCScoreIfChatOn(p, e);
obj.getScore(p.getName()) obj.getScore(p.getName())
.setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID .setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID
@ -303,22 +307,24 @@ public class ChatProcessing {
return formatters; return formatters;
} }
static void doFunStuff(CommandSender sender, String message) { static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) {
if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F")) if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F"))
PlayerListener.Fs.add(sender); PlayerListener.Fs.add(sender);
String msg = message.toLowerCase(); String msg = message.toLowerCase();
if (msg.contains("lol")) { val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime());
UnlolCommand.Lastlolornot = true; boolean add = false;
UnlolCommand.Lastlol = sender; if (add = msg.contains("lol"))
} else { lld.setLolornot(true);
else {
for (int i = 0; i < PlayerListener.LaughStrings.length; i++) { for (int i = 0; i < PlayerListener.LaughStrings.length; i++) {
if (msg.contains(PlayerListener.LaughStrings[i])) { if (add = msg.contains(PlayerListener.LaughStrings[i])) {
UnlolCommand.Lastlol = sender; lld.setLolornot(false);
UnlolCommand.Lastlolornot = false;
break; break;
} }
} }
} }
if (add)
UnlolCommand.Lastlol.put(event.getChannel(), lld);
} }
} }

View file

@ -337,7 +337,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
if (town == null) if (town == null)
return new RecipientTestResult("You aren't in a town."); return new RecipientTestResult("You aren't in a town.");
Nation nation = null; Nation nation = null;
int index = -1; int index;
if (nationchat) { if (nationchat) {
if (town.hasNation()) if (town.hasNation())
nation = town.getNation(); nation = town.getNation();

View file

@ -1,19 +1,24 @@
package buttondevteam.chat.commands; package buttondevteam.chat.commands;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit; 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 org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.chat.Channel;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
import lombok.Data;
@CommandClass(modOnly = false) @CommandClass(modOnly = false)
public final class UnlolCommand extends TBMCCommandBase { public final class UnlolCommand extends TBMCCommandBase {
public static CommandSender Lastlol = null; public static Map<Channel, LastlolData> Lastlol = new HashMap<>();
public static boolean Lastlolornot;
@Override @Override
public String[] GetHelpText(String alias) { public String[] GetHelpText(String alias) {
@ -25,16 +30,26 @@ public final class UnlolCommand extends TBMCCommandBase {
@Override @Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) { public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (Lastlol != null) { LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender))
if (Lastlol instanceof Player) .max((lld1, lld2) -> Long.compare(lld1.Loltime, lld2.Loltime)).orElse(null);
((Player) Lastlol) if (lol == null)
.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false)); return true;
String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) if (lol.Lolowner instanceof Player)
+ (Lastlolornot ? " unlolled " : " unlaughed ") ((Player) lol.Lolowner)
+ (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName()); .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false));
Bukkit.broadcastMessage(msg); String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName())
Lastlol = null; + (lol.Lolornot ? " unlolled " : " unlaughed ")
} + (lol.Lolowner instanceof Player ? ((Player) lol.Lolowner).getDisplayName() : lol.Lolowner.getName());
Bukkit.broadcastMessage(msg);
Lastlol.remove(lol.Chatevent.getChannel());
return true; return true;
} }
@Data
public static class LastlolData {
private boolean Lolornot;
private final CommandSender Lolowner;
private final TBMCChatEventBase Chatevent;
private final long Loltime;
}
} }

View file

@ -16,6 +16,7 @@ import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.FlairStates; import buttondevteam.chat.FlairStates;
import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PlayerJoinTimerTask;
import buttondevteam.chat.PluginMain; import buttondevteam.chat.PluginMain;
import buttondevteam.chat.commands.UnlolCommand;
import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import buttondevteam.lib.player.TBMCPlayerLoadEvent; import buttondevteam.lib.player.TBMCPlayerLoadEvent;
import buttondevteam.lib.player.TBMCPlayerSaveEvent; import buttondevteam.lib.player.TBMCPlayerSaveEvent;
@ -111,6 +112,7 @@ public class PlayerJoinLeaveListener implements Listener {
} }
if (deletenick != null) if (deletenick != null)
PlayerListener.nicknames.remove(deletenick); PlayerListener.nicknames.remove(deletenick);
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
} }
} }