Updated repeating task for unmuting players

This commit is contained in:
Aust1n46 2020-08-24 18:15:31 -05:00
parent 20e440b137
commit f82af0761c
5 changed files with 95 additions and 105 deletions

View File

@ -76,6 +76,8 @@ SpyOff: '&6You are no longer spying.'
SpyOn: '&6You are now spying.'
UnblockCommandPlayer: '&cYou have been unblocked from entering command {command}.'
UnblockCommandSender: '&cUnblocked player &6{player} &cfrom entering command {command}.'
UnitsPlural: 'minutes'
UnitsSingular: 'minute'
UnmutePlayerAllPlayer: '&cYou have just been unmuted in all channels.'
UnmutePlayerAllSender: '&cUnmuted player &6{player} &cin all channels.'
UnmutePlayerPlayer: '&cYou have just been unmuted in: {channel_color}{channel_name}'

View File

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -419,26 +420,36 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
scheduler.runTaskTimerAsynchronously(this, new Runnable() {
@Override
public void run() {
for(MineverseChatPlayer p : MineverseChat.players) {
int time = (int) (System.currentTimeMillis() / 60000);
for(String c : p.getMutes().keySet()) {
ChatChannel channel = ChatChannel.getChannel(c);
for (MineverseChatPlayer p : MineverseChat.onlinePlayers) {
int time = (int) System.currentTimeMillis();
Iterator<String> iterator = p.getMutes().keySet().iterator();
while (iterator.hasNext()) {
ChatChannel channel = ChatChannel.getChannel(iterator.next());
int timemark = p.getMutes().get(channel.getName());
if(timemark == 0) return;
// System.out.println(time + " " + timemark);
if(time > timemark) {
p.removeMute(channel.getName());
if(p.isOnline()) p.getPlayer().sendMessage(ChatColor.RED + "You have just been unmuted in: " + channel.getColor() + channel.getName());
else p.setModified(true);
if (timemark == 0) {
return;
}
if (getConfig().getString("loglevel", "info").equals("debug")) {
System.out.println(time + " " + timemark);
}
if (time >= timemark) {
iterator.remove();
if (p.isOnline()) {
p.getPlayer().sendMessage(LocalizedMessage.UNMUTE_PLAYER_PLAYER.toString()
.replace("{player}", p.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
} else {
p.setModified(true);
}
}
}
}
if(getConfig().getString("loglevel", "info").equals("debug")) {
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
if (getConfig().getString("loglevel", "info").equals("debug")) {
Bukkit.getConsoleSender()
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
}
}
}, 0L, 1200L); //one minute interval
}
}, 0L, 1200L); // one minute interval
this.firstRun = false;
}

View File

@ -10,6 +10,7 @@ import mineverse.Aust1n46.chat.command.MineverseCommand;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
public class Mute extends MineverseCommand {
private static final int MILLISECONDS_PER_MINUTE = 60000;
public Mute(String name) {
super(name);
@ -17,115 +18,97 @@ public class Mute extends MineverseCommand {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender.hasPermission("venturechat.mute")) {
if(args.length < 2) {
sender.sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS.toString()
.replace("{command}", "/mute")
if (sender.hasPermission("venturechat.mute")) {
if (args.length < 2) {
sender.sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS.toString().replace("{command}", "/mute")
.replace("{args}", "[player] [channel] {time}"));
return;
}
MineverseChatPlayer player = MineverseChatAPI.getMineverseChatPlayer(args[0]);
if(player == null || (!player.isOnline() && !sender.hasPermission("venturechat.mute.offline"))) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
if (player == null || (!player.isOnline() && !sender.hasPermission("venturechat.mute.offline"))) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", args[0]));
return;
}
if(args.length == 2) {
if(ChatChannel.isChannel(args[1])) {
if (args.length == 2) {
if (ChatChannel.isChannel(args[1])) {
ChatChannel channel = ChatChannel.getChannel(args[1]);
if(player.isMuted(channel.getName())) {
if (player.isMuted(channel.getName())) {
sender.sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
return;
}
if(channel.isMutable()) {
if (channel.isMutable()) {
player.addMute(channel.getName(), 0);
sender.sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
if(player.isOnline())
player.getPlayer().sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName()));
else
if (player.isOnline())
player.getPlayer()
.sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER.toString()
.replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
else
player.setModified(true);
if(channel.getBungee()) {
if (channel.getBungee()) {
MineverseChat.getInstance().synchronize(player, true);
}
return;
}
sender.sendMessage(LocalizedMessage.CHANNEL_CANNOT_MUTE.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
return;
}
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[1]));
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[1]));
return;
}
if(ChatChannel.isChannel(args[1])) {
}
if (ChatChannel.isChannel(args[1])) {
ChatChannel channel = ChatChannel.getChannel(args[1]);
if(player.isMuted(channel.getName())) {
if (player.isMuted(channel.getName())) {
sender.sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
return;
}
if(channel.isMutable()) {
if (channel.isMutable()) {
try {
//Calendar currentDate = Calendar.getInstance();
//SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss");
//String date = formatter.format(currentDate.getTime());
//String[] datearray = date.split(":");
//int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2]));
int datetime = (int) (System.currentTimeMillis() / 60000);
int datetime = (int) System.currentTimeMillis();
int time = Integer.parseInt(args[2]);
if(time > 0) {
player.addMute(channel.getName(), datetime + time);
String keyword = "minutes";
if(time == 1)
keyword = "minute";
if (time > 0) {
player.addMute(channel.getName(), datetime + (time * MILLISECONDS_PER_MINUTE));
String units = LocalizedMessage.UNITS_PLURAL.toString();
if (time == 1)
units = LocalizedMessage.UNITS_SINGULAR.toString();
sender.sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName())
.replace("{time}", time + "")
.replace("{units}", keyword));
if(player.isOnline())
player.getPlayer().sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_TIME.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName())
.replace("{time}", time + "")
.replace("{units}", keyword));
.replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()).replace("{time}", time + "")
.replace("{units}", units));
if (player.isOnline())
player.getPlayer()
.sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_TIME.toString()
.replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName())
.replace("{time}", time + "").replace("{units}", units));
else
player.setModified(true);
if(channel.getBungee()) {
if (channel.getBungee()) {
MineverseChat.getInstance().synchronize(player, true);
}
return;
}
sender.sendMessage(LocalizedMessage.INVALID_TIME.toString()
.replace("{args}", args[2]));
}
catch(Exception e) {
sender.sendMessage(LocalizedMessage.INVALID_TIME.toString()
.replace("{args}", args[2]));
sender.sendMessage(LocalizedMessage.INVALID_TIME.toString().replace("{args}", args[2]));
} catch (Exception e) {
sender.sendMessage(LocalizedMessage.INVALID_TIME.toString().replace("{args}", args[2]));
}
return;
}
sender.sendMessage(LocalizedMessage.CHANNEL_CANNOT_MUTE.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName()));
.replace("{channel_color}", channel.getColor()).replace("{channel_name}", channel.getName()));
return;
}
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[1]));
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[1]));
return;
}
sender.sendMessage(LocalizedMessage.COMMAND_NO_PERMISSION.toString());

View File

@ -17,53 +17,45 @@ public class Unmute extends MineverseCommand {
@Override
public void execute(CommandSender sender, String command, String[] args) {
if(sender.hasPermission("venturechat.mute")) {
if(args.length < 2) {
sender.sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS.toString()
.replace("{command}", "/unmute")
if (sender.hasPermission("venturechat.mute")) {
if (args.length < 2) {
sender.sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS.toString().replace("{command}", "/unmute")
.replace("{args}", "[player] [channel]"));
return;
}
MineverseChatPlayer player = MineverseChatAPI.getMineverseChatPlayer(args[0]);
if(player == null || (!player.isOnline() && !sender.hasPermission("venturechat.mute.offline"))) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
if (player == null || (!player.isOnline() && !sender.hasPermission("venturechat.mute.offline"))) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", args[0]));
return;
}
for(ChatChannel channel : ChatChannel.getChannels()) {
if(channel.getName().equalsIgnoreCase(args[1]) || channel.getAlias().equalsIgnoreCase(args[1])) {
if(!player.isMuted(channel.getName())) {
for (ChatChannel channel : ChatChannel.getChannels()) {
if (channel.getName().equalsIgnoreCase(args[1]) || channel.getAlias().equalsIgnoreCase(args[1])) {
if (!player.isMuted(channel.getName())) {
sender.sendMessage(LocalizedMessage.PLAYER_NOT_MUTED.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
return;
}
player.removeMute(channel.getName());
player.removeMute(channel.getName());
sender.sendMessage(LocalizedMessage.UNMUTE_PLAYER_SENDER.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
if(player.isOnline()) {
if (player.isOnline()) {
player.getPlayer().sendMessage(LocalizedMessage.UNMUTE_PLAYER_PLAYER.toString()
.replace("{player}", player.getName())
.replace("{channel_color}", channel.getColor() + "")
.replace("{player}", player.getName()).replace("{channel_color}", channel.getColor())
.replace("{channel_name}", channel.getName()));
}
else {
} else {
player.setModified(true);
}
if(channel.getBungee()) {
if (channel.getBungee()) {
MineverseChat.getInstance().synchronize(player, true);
}
return;
}
}
}
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString()
.replace("{args}", args[1]));
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[1]));
return;
}
else {
} else {
sender.sendMessage(LocalizedMessage.COMMAND_NO_PERMISSION.toString());
return;
}

View File

@ -83,6 +83,8 @@ public enum LocalizedMessage {
SPY_ON("SpyOn"),
UNBLOCK_COMMAND_PLAYER("UnblockCommandPlayer"),
UNBLOCK_COMMAND_SENDER("UnblockCommandSender"),
UNITS_PLURAL("UnitsPlural"),
UNITS_SINGULAR("UnitsSingular"),
UNMUTE_PLAYER_ALL_PLAYER("UnmutePlayerAllPlayer"),
UNMUTE_PLAYER_ALL_SENDER("UnmutePlayerAllSender"),
UNMUTE_PLAYER_PLAYER("UnmutePlayerPlayer"),