TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_clearchat.java

71 lines
2.7 KiB
Java
Raw Normal View History

2019-01-11 17:04:32 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.stream.IntStream;
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
import me.totalfreedom.totalfreedommod.playerverification.VPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Clears the chat for players who are not opt-out.", usage = "/<command>", aliases = "cc")
2019-01-11 17:04:32 +00:00
public class Command_clearchat extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
2019-01-12 03:05:12 +00:00
2019-01-11 17:04:32 +00:00
if (plugin.al.isAdmin(playerSender))
{
2019-01-12 03:05:12 +00:00
for (Player player : server.getOnlinePlayers())
{
boolean optedOut = false;
if (plugin.al.isAdmin(player))
{
optedOut = true;
}
else if (plugin.mbl.isMasterBuilder(player) && plugin.mbl.getMasterBuilder(player).isClearChatOptOut())
{
optedOut = true;
}
else if (plugin.pv.getVerificationPlayer(player).getEnabled() && plugin.pv.getVerificationPlayer(player).isClearChatOptOut())
{
optedOut = true;
}
if (!optedOut)
{
IntStream.range(0, 100).mapToObj(i -> "").forEach(player::sendMessage);
}
}
2019-01-11 17:04:32 +00:00
FUtil.adminAction(sender.getName(), "Cleared chat", true);
}
2019-01-12 03:05:12 +00:00
else if (plugin.mbl.isMasterBuilder(playerSender))
2019-01-11 17:04:32 +00:00
{
MasterBuilder mb = plugin.mbl.getMasterBuilder(playerSender);
mb.setClearChatOptOut(!mb.isClearChatOptOut());
2019-01-12 03:05:12 +00:00
msg((mb.isClearChatOptOut() ? "Opted-out of" : "Opted-in to") + " clear chat.");
2019-01-11 17:04:32 +00:00
plugin.mbl.save();
plugin.mbl.updateTables();
}
2019-01-12 03:05:12 +00:00
else if (plugin.pv.getVerificationPlayer(playerSender).getEnabled())
2019-01-11 17:04:32 +00:00
{
VPlayer vp = plugin.pv.getVerificationPlayer(playerSender);
vp.setClearChatOptOut(!vp.isClearChatOptOut());
2019-01-12 03:05:12 +00:00
msg((vp.isClearChatOptOut() ? "Opted-out of" : "Opted-in to") + " clear chat.");
2019-01-11 17:04:32 +00:00
plugin.pv.saveVerificationData(vp);
return true;
}
2019-01-12 03:05:12 +00:00
else
{
msg("Only Master Builders, admins, and players with verification enabled can opt-out of clear chat.", ChatColor.RED);
}
2019-01-11 17:04:32 +00:00
return true;
}
}