add clearchat

This commit is contained in:
Lemon 2019-01-11 22:04:32 +05:00
parent 8c7823d7bf
commit f649e3d6c3
4 changed files with 70 additions and 24 deletions

View File

@ -3,18 +3,16 @@ package me.totalfreedom.totalfreedommod.blocking;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.MaterialGroup; import me.totalfreedom.totalfreedommod.util.MaterialGroup;
import org.bukkit.ChatColor;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.Block;
import org.bukkit.block.ShulkerBox; import org.bukkit.block.ShulkerBox;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
@ -29,7 +27,6 @@ import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FireworkExplodeEvent; import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;
@ -163,8 +160,7 @@ public class EventBlocker extends FreedomService
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onLeavesDecay(LeavesDecayEvent event public void onLeavesDecay(LeavesDecayEvent event)
)
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -225,16 +221,7 @@ public class EventBlocker extends FreedomService
{ {
BlockStateMeta blockStateMeta = (BlockStateMeta)item.getItemMeta(); BlockStateMeta blockStateMeta = (BlockStateMeta)item.getItemMeta();
ShulkerBox shulkerBox = (ShulkerBox)blockStateMeta.getBlockState(); ShulkerBox shulkerBox = (ShulkerBox)blockStateMeta.getBlockState();
for (ItemStack itemStack : shulkerBox.getInventory().getContents()) shulkerBox.getInventory().clear();
{
if (itemStack != null)
{
event.setCancelled(true);
break;
} }
} }
} }
}
}

View File

@ -0,0 +1,51 @@
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 = "Clear chat", usage = "/<command> [optout]", aliases = "cc")
public class Command_clearchat extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (plugin.al.isAdmin(playerSender))
{
server.getOnlinePlayers().stream().filter(player -> !plugin.al.isAdmin(player) || !plugin.pv.getVerificationPlayer(player).isClearChatOptOut() || !plugin.mbl.getMasterBuilder(player).isClearChatOptOut()).forEach(player -> IntStream.range(0, 100).mapToObj(i -> "").forEach(player::sendMessage));
FUtil.adminAction(sender.getName(), "Cleared chat", true);
return true;
}
if (args.length != 1)
{
return false;
}
if (plugin.mbl.isMasterBuilder(playerSender))
{
MasterBuilder mb = plugin.mbl.getMasterBuilder(playerSender);
mb.setClearChatOptOut(!mb.isClearChatOptOut());
msg(mb.isClearChatOptOut() ? "Opted-out" : "Opted-in" + " to clear chat.");
plugin.mbl.save();
plugin.mbl.updateTables();
return true;
}
if (plugin.pv.getVerificationPlayer(playerSender).getEnabled())
{
VPlayer vp = plugin.pv.getVerificationPlayer(playerSender);
vp.setClearChatOptOut(!vp.isClearChatOptOut());
msg(vp.isClearChatOptOut() ? "Opted-out" : "Opted-in" + " to clear chat.");
plugin.pv.saveVerificationData(vp);
return true;
}
msg("Only Master Builders, and players with verification enabled can opt out of clear chat.", ChatColor.RED);
return true;
}
}

View File

@ -34,6 +34,9 @@ public class MasterBuilder implements ConfigLoadable, ConfigSavable, Validatable
@Getter @Getter
@Setter @Setter
private String tag = null; private String tag = null;
@Getter
@Setter
private boolean clearChatOptOut = false;
public static final String CONFIG_FILENAME = "masterbuilders.yml"; public static final String CONFIG_FILENAME = "masterbuilders.yml";
@ -58,7 +61,8 @@ public class MasterBuilder implements ConfigLoadable, ConfigSavable, Validatable
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n") .append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n") .append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
.append("- Discord ID: ").append(discordID).append("\n") .append("- Discord ID: ").append(discordID).append("\n")
.append("- Tag: ").append(tag).append("\n"); .append("- Tag: ").append(tag).append("\n")
.append("- Clear Chat Opt Out: ").append(clearChatOptOut);
return output.toString(); return output.toString();
} }
@ -80,6 +84,7 @@ public class MasterBuilder implements ConfigLoadable, ConfigSavable, Validatable
lastLogin = FUtil.stringToDate(cs.getString("last_login")); lastLogin = FUtil.stringToDate(cs.getString("last_login"));
discordID = cs.getString("discord_id", null); discordID = cs.getString("discord_id", null);
tag = cs.getString("tag", null); tag = cs.getString("tag", null);
clearChatOptOut = cs.getBoolean("clearchatoptout", false);
} }
@Override @Override
@ -91,6 +96,7 @@ public class MasterBuilder implements ConfigLoadable, ConfigSavable, Validatable
cs.set("last_login", FUtil.dateToString(lastLogin)); cs.set("last_login", FUtil.dateToString(lastLogin));
cs.set("discord_id", discordID); cs.set("discord_id", discordID);
cs.set("tag", tag); cs.set("tag", tag);
cs.set("clearchatoptout", clearChatOptOut);
} }
public void addIp(String ip) public void addIp(String ip)
@ -110,12 +116,9 @@ public class MasterBuilder implements ConfigLoadable, ConfigSavable, Validatable
} }
public void removeIp(String ip) public void removeIp(String ip)
{
if (ips.contains(ip))
{ {
ips.remove(ip); ips.remove(ip);
} }
}
public void clearIPs() public void clearIPs()
{ {

View File

@ -31,6 +31,9 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
@Getter @Getter
@Setter @Setter
private String tag = null; private String tag = null;
@Getter
@Setter
private boolean clearChatOptOut = false;
public VPlayer(String name) public VPlayer(String name)
{ {
@ -51,6 +54,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
discordId = cs.getString("discordId", null); discordId = cs.getString("discordId", null);
enabled = cs.getBoolean("enabled", false); enabled = cs.getBoolean("enabled", false);
tag = cs.getString("tag", null); tag = cs.getString("tag", null);
clearChatOptOut = cs.getBoolean("clearchatoptout", false);
} }
@Override @Override
@ -62,6 +66,7 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
cs.set("enabled", enabled); cs.set("enabled", enabled);
cs.set("tag", tag); cs.set("tag", tag);
cs.set("ips", Lists.newArrayList(ips)); cs.set("ips", Lists.newArrayList(ips));
cs.set("clearchatoptout", clearChatOptOut);
} }
public List<String> getIps() public List<String> getIps()
@ -71,12 +76,12 @@ public class VPlayer implements ConfigLoadable, ConfigSavable, Validatable
public boolean addIp(String ip) public boolean addIp(String ip)
{ {
return ips.contains(ip) ? false : ips.add(ip); return !ips.contains(ip) && ips.add(ip);
} }
public boolean removeIp(String ip) public void removeIp(String ip)
{ {
return ips.remove(ip); ips.remove(ip);
} }
@Override @Override