Added slowmode.
This commit is contained in:
parent
35f217e943
commit
f5e906ce54
|
@ -284,3 +284,9 @@ target/classes/com/songoda/ultimatemoderation/utils/Metrics\$SimpleBarChart\.cla
|
|||
target/classes/com/songoda/ultimatemoderation/utils/Metrics\$SimplePie\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/utils/Metrics\$SingleLineChart\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/command/commands/CommandSlowMode\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/listeners/ChatListener\$Log\.class
|
||||
|
||||
target/classes/com/songoda/ultimatemoderation/tasks/SlowModeTask\.class
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.songoda.ultimatemoderation.storage.Storage;
|
|||
import com.songoda.ultimatemoderation.storage.StorageRow;
|
||||
import com.songoda.ultimatemoderation.storage.types.StorageMysql;
|
||||
import com.songoda.ultimatemoderation.storage.types.StorageYaml;
|
||||
import com.songoda.ultimatemoderation.tasks.SlowModeTask;
|
||||
import com.songoda.ultimatemoderation.tickets.Ticket;
|
||||
import com.songoda.ultimatemoderation.tickets.TicketManager;
|
||||
import com.songoda.ultimatemoderation.tickets.TicketResponse;
|
||||
|
@ -108,6 +109,9 @@ public class UltimateModeration extends JavaPlugin {
|
|||
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);
|
||||
|
||||
// Start tasks
|
||||
SlowModeTask.startTask(this);
|
||||
|
||||
// Starting Metrics
|
||||
new Metrics(this);
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ public class CommandManager implements CommandExecutor {
|
|||
instance.getCommand("RunTemplate").setExecutor(this);
|
||||
instance.getCommand("Ticket").setExecutor(this);
|
||||
instance.getCommand("StaffChat").setExecutor(this);
|
||||
instance.getCommand("SlowMode").setExecutor(this);
|
||||
|
||||
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
||||
addCommand(new CommandClearChat());
|
||||
|
@ -64,6 +65,7 @@ public class CommandManager implements CommandExecutor {
|
|||
addCommand(new CommandRunTemplate());
|
||||
addCommand(new CommandTicket());
|
||||
addCommand(new CommandStaffChat());
|
||||
addCommand(new CommandSlowMode());
|
||||
|
||||
addCommand(new CommandSettings(commandUltimateModeration));
|
||||
addCommand(new CommandHelp(commandUltimateModeration));
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSlowMode extends AbstractCommand {
|
||||
|
||||
public CommandSlowMode() {
|
||||
super(true, true, "Slowmode");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
long delay = Methods.parseTime(args[0]);
|
||||
|
||||
if (delay == 0)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
ChatListener.setSlowModeOverride(delay);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player ->
|
||||
player.sendMessage(instance.getReferences().getPrefix() +
|
||||
instance.getLocale().getMessage("event.slowmode.enabled",(delay / 1000))));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length == 1) {
|
||||
List<String> players = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
players.add(player.getName());
|
||||
}
|
||||
return players;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.slowmode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/slowmode <delay>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to see inside of a players inventory.";
|
||||
}
|
||||
}
|
|
@ -5,18 +5,19 @@ import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
|||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.staffchat.StaffChannel;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.songoda.ultimatemoderation.utils.SettingsManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
private static long slowModeOverride = 0;
|
||||
|
||||
private static boolean isChatToggled = true; // true means people can talk, false means muted
|
||||
private UltimateModeration instance;
|
||||
|
||||
|
@ -28,10 +29,29 @@ public class ChatListener implements Listener {
|
|||
isChatToggled = toggled;
|
||||
}
|
||||
|
||||
private static List<Log> chatLog = new ArrayList<>();
|
||||
|
||||
public static long getSlowModeOverride() {
|
||||
return slowModeOverride;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
long slowmode = slowModeOverride == 0 ? Methods.parseTime(SettingsManager.Setting.SLOW_MODE.getString()) : slowModeOverride;
|
||||
|
||||
if (!player.hasPermission("um.slowmode.bypass") && slowmode != 0) {
|
||||
List<Log> chats = chatLog.stream().filter(log -> log.player == player.getUniqueId()).collect(Collectors.toList());
|
||||
if (chats.size() != 0) {
|
||||
Log last = chats.get(chats.size() - 1);
|
||||
if ((System.currentTimeMillis() - last.sent) < slowmode) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) {
|
||||
if (!channel.listMembers().contains(player.getUniqueId())) continue;
|
||||
event.setCancelled(true);
|
||||
|
@ -48,6 +68,44 @@ public class ChatListener implements Listener {
|
|||
appliedPunishments.get(0).sendMessage(player);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
// Log chat.
|
||||
chatLog.add(new Log(player.getUniqueId(), System.currentTimeMillis(), event.getMessage()));
|
||||
|
||||
}
|
||||
|
||||
public static void setSlowModeOverride(long slowModeOverride) {
|
||||
ChatListener.slowModeOverride = slowModeOverride;
|
||||
}
|
||||
|
||||
public static List<Log> getLogs() {
|
||||
return new ArrayList<>(chatLog);
|
||||
}
|
||||
|
||||
public class Log {
|
||||
|
||||
private UUID player;
|
||||
private long sent;
|
||||
private String message;
|
||||
|
||||
Log(UUID player, long sent, String message) {
|
||||
this.player = player;
|
||||
this.sent = sent;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public long getSent() {
|
||||
return sent;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.songoda.ultimatemoderation.tasks;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.SettingsManager;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SlowModeTask extends BukkitRunnable {
|
||||
|
||||
private static SlowModeTask instance;
|
||||
private static UltimateModeration plugin;
|
||||
|
||||
private SlowModeTask(UltimateModeration plug) {
|
||||
plugin = plug;
|
||||
}
|
||||
|
||||
public static SlowModeTask startTask(UltimateModeration plug) {
|
||||
plugin = plug;
|
||||
if (instance == null) {
|
||||
instance = new SlowModeTask(plugin);
|
||||
instance.runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long slowmode = ChatListener.getSlowModeOverride() == 0 ? Methods.parseTime(SettingsManager.Setting.SLOW_MODE.getString()) : ChatListener.getSlowModeOverride();
|
||||
|
||||
if (slowmode == 0) return;
|
||||
|
||||
List<ChatListener.Log> logs = ChatListener.getLogs();
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (player.hasPermission("um.slowmode.bypass")) return;
|
||||
|
||||
List<ChatListener.Log> chats = logs.stream().filter(log -> log.getPlayer() == player.getUniqueId()).collect(Collectors.toList());
|
||||
if (chats.size() == 0) return;
|
||||
ChatListener.Log last = chats.get(chats.size() - 1);
|
||||
|
||||
if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) {
|
||||
int remaining = (int)((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000);
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0 ? plugin.getLocale().getMessage("event.slowmode.done") : plugin.getLocale().getMessage("event.slowmode.wait", remaining)));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -172,6 +172,7 @@ public class SettingsManager implements Listener {
|
|||
VANISH_SOUND("Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE"),
|
||||
VANISH_BATS("Main.Release Bats On Vanish", true),
|
||||
VANISH_PARTICLE("Main.Vanish Particle", "EXPLOSION_NORMAL"),
|
||||
SLOW_MODE("Main.SLOW_MODE", "0s"),
|
||||
|
||||
BLOCKED_COMMANDS("Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl")),
|
||||
|
||||
|
|
|
@ -61,6 +61,10 @@ event.staffchat.format.join = "&%color%[%channel%] %player% has just joined the
|
|||
event.staffchat.format.leave = "&%color%[%channel%] %player% has just left the channel."
|
||||
event.staffchat.format = "&%color%[%channel%] %player%&%color%: %message%"
|
||||
|
||||
event.slowmode.wait = "&7Slow mode &6%delay% &7seconds left."
|
||||
event.slowmode.done = "&7Slow mode time out."
|
||||
event.slowmode.enabled = "&7Slow mode has been enabled with the delay &6%delay% &7seconds."
|
||||
|
||||
#GUI Messages
|
||||
|
||||
gui.general.previous = "&6Previous Page"
|
||||
|
@ -143,7 +147,7 @@ gui.notes.title = "&8%tonotes% > Notes"
|
|||
gui.notes.create = "&6Create Note"
|
||||
gui.notes.remove = "&cClick to remove"
|
||||
gui.notes.type = "Type in your note."
|
||||
gui.notes.createdon = "&7Created on &6%time%&7."
|
||||
gui.notes.createdon = "&7Created on &6%sent%&7."
|
||||
gui.notes.createdby = "&7Created by &6%player%&7."
|
||||
|
||||
|
||||
|
@ -159,7 +163,7 @@ gui.ticket.title = "&8Tickets > %id%";
|
|||
gui.ticket.type = "&7Type &6%type%&7."
|
||||
gui.ticket.picktype = "&8Pick a ticket type.";
|
||||
gui.ticket.clicktotele = "&6Teleport to ticket location.";
|
||||
gui.ticket.createdon = "&7Created on &6%time%&7."
|
||||
gui.ticket.createdon = "&7Created on &6%sent%&7."
|
||||
gui.ticket.respond = "&6Respond"
|
||||
gui.ticket.status = "&7Status &6%status%&7."
|
||||
gui.ticket.postedby = "&7Posted by &6%player%&7."
|
||||
|
|
|
@ -91,4 +91,9 @@ commands:
|
|||
description: StaffChat
|
||||
defaullt: false
|
||||
aliases: [sc]
|
||||
usage: /staffchat
|
||||
usage: /staffchat
|
||||
SlowMode:
|
||||
description: SlowMode
|
||||
default: false
|
||||
aliases: [sm]
|
||||
ussage: /slowmode
|
Loading…
Reference in New Issue